Pic Microcontroller Issue Help Needed

Thread Starter

SoaringFree

Joined Sep 15, 2016
20
Hello, all!
I am having an issue with migration of a program written for Pic microcontroller that I wondered if anyone would know how to correct.
This program was originally written in assembly language for a PIC12F615 and was successfully migrated to PIC12HV615, PIC12F617, AND PIC16F684 with no issues. I now have tried to migrate this code to a PIC12F1840 enhanced midrange microcontroller. I have step by step very methodically changed over this program and have had success up to the point that I get up to a program line of say 1125 and my program does not work correctly. I am using MPLABX IDE and confirm with an oscilloscope. I have isolated a part of the program which uses CCP to capture a falling edge and check the code, I know the code is correct as I have used this code on the above mentioned PICS and following the datasheet to make sure my BANK selection is correct. I have tried moving my variables used in this section of code into 0x70 section of memory which is shared between all banks, but did not have any luck with it. I finally took this code and moved it from around the program line 1125 to the start of my program which is after the initialization and macros etc and ran it in simulation and on my oscilloscope and it works.
From the information above can anyone see what the issue is that I can not find as to why the code will not work at this point with this microcontroller? I migrated to the PIC 12F1840 because I want to use the USART and EEPROM sections also. I do not think it is a paging issue as I am still within 2048 words of code.

Suggestions?

Thank you all for your time and help.

Lisa
 

jpanhalt

Joined Jan 18, 2008
11,087
Post your code. PIC 12F683 assembly code goes very easily to the 12F1840 as does 16F1xxx code. Are you naming the ports correctly?

John
 

Thread Starter

SoaringFree

Joined Sep 15, 2016
20
Thank you John for your reply,
I can not post code because of proprietary reasons. Yes ports are named correctly. I am baffled because this code works over multiple PICS but I for some reason cant get this to work on the PIC12F1840. Is there any reason why after you get above 1000 lines of code that the program would become lost?


Lisa
 

AlbertHall

Joined Jun 4, 2014
12,338
Without seeing the code it is only possible to guess.
My guess is that you are crossing a flash memory page boundary. Read section 3,3 PCL and PCLATH of the datasheet.
 

JohnInTX

Joined Jun 26, 2012
4,787
Without seeing the code it is only possible to guess.
My guess is that you are crossing a flash memory page boundary. Read section 3,3 PCL and PCLATH of the datasheet.
+1 Especially be sure to explicitly point PCLATH to the bank that any interrupt service routine is in. If you don't, the jump to service could be to the wrong bank.
If you are using tables, ensure that you take page AND bank boundaries into account.
Code won't flow across the banks, you have to set PCLATH.
After you set PCLATH prior to a CALL, don't forget to set it back to the current bank.
Errata says that BRA and BRW don't always work right with interrupts on some silicon revs.
Line numbers aren't particularly useful. Its more important to know what the hex address of the line is.. even without the source.

I'm with the others, as your code got bigger, it sounds like you aren't managing the ()*&%*&$^**&&#*I (uh.. easy) banking stuff.
 
Last edited:

Thread Starter

SoaringFree

Joined Sep 15, 2016
20
+1 Especially be sure to explicitly point PCLATH to the bank that any interrupt service routine is in. If you don't, the jump to service could be to the wrong bank.
If you are using tables, ensure that you take page AND bank boundaries into account.
Code won't flow across the banks, you have to set PCLATH.
After you set PCLATH prior to a CALL, don't forget to set it back to the current bank.
Errata says that BRA and BRW don't always work right with interrupts on some silicon revs.
Line numbers aren't particularly useful. Its more important to know what the hex address of the line is.. even without the source.
as an ec
I'm with the others, as your code got bigger, it sounds like you aren't managing the ()*&%*&$^**&&#*I (uh.. easy) banking stuff.
Thank you for your reply.
With the banking concern, the way that I deal with the banking is to use "movlb 0x00" placed before a move to , let's say, bank 0.
for example: movlb 0x05
bsf
 

Thread Starter

SoaringFree

Joined Sep 15, 2016
20
Thank you for your reply.
With the banking concern, the way that I deal with the banking is to use "movlb 0x00" placed before a move to , let's say, bank 0.
for example: movlb 0x05
bsf
Thank you for your reply.
With the banking concern, the way that I deal with the banking is to use "movlb 0x00" placed before a move to , let's say, bank 0.
for example: movlb 0x05
bsf ccp1con, 0
movlb 0x00
clrf TMR1L
That is how I change banks. Is there a better way? From reading the datasheet that is how I understood it to be done.

TY,
Lisa
 

JohnInTX

Joined Jun 26, 2012
4,787
Thank you for your reply.
With the banking concern, the way that I deal with the banking is to use "movlb 0x00" placed before a move to , let's say, bank 0.
for example: movlb 0x05
bsf ccp1con, 0
movlb 0x00
clrf TMR1L
That is how I change banks. Is there a better way? From reading the datasheet that is how I understood it to be done.

TY,
Lisa
movlb has to do with RAM banks. The program code crossing banks is different and needs attention paid to PCLATH. Maybe that is why the perfectly reasonable move to common RAM failed as the code got bigger.
Does the code cross ROM banks i.e. address >= 800h? See the program listing file to know..
Good luck.
 

Thread Starter

SoaringFree

Joined Sep 15, 2016
20
movlb has to do with RAM banks. The program code crossing banks is different and needs attention paid to PCLATH. Maybe that is why the perfectly reasonable move to common RAM failed as the code got bigger.
Does the code cross ROM banks i.e. address >= 800h? See the program listing file to know..
Good luck.
Thanks John for all your help, I will Check for my errorrs and be back here tomorrow with my findings,

Lisa
 

jpanhalt

Joined Jan 18, 2008
11,087
While memory paging can be an issue, that issue would also affect the other mid-range chips on which this code works. I would look for the differences between the chips. As for the banking, have you searched the old code to see if there are any RPo/RP1 or IRP's that have been missed? I would search by both the alphanumeric name as well as the STATUS bit number. Indirect addressing on the 12F1840 is done a little differently than on the other chips.

While you can still read and write to a port in the 12F1840 in Bank0, if you happened to change to LATA, then you need to be sure you change to Bank2 for doing that.

John
 

jayanthd

Joined Jul 4, 2015
945
If you can't show the code then tell me in detail what the device has to do and when and I will write a C Code for PIC12F1840 and you pay me 200 USD. :)
 

jayanthd

Joined Jul 4, 2015
945
WoW !

TS is not asking for a service...He wants help.
How can I help without the code ?

I think PIC12F1840 uses ANSELx or ANSELA registers. I have not checked the datasheet. The other PICs which you mentioned doesn't use ANSELx or ANSELA registers for ADC configuration. Maybe this is causing the problem. Configure ADC registers properly.
 

jpanhalt

Joined Jan 18, 2008
11,087
How can I help without the code ?

I think PIC12F1840 uses ANSELx or ANSELA registers. I have not checked the datasheet. The other PICs which you mentioned doesn't use ANSELx or ANSELA registers for ADC configuration. Maybe this is causing the problem. Configure ADC registers properly.
The 12F615 and 16F684 most certainly do have ANSEL, which must be correctly set for analog or digital inputs. Perhaps your code is only worth 2¢, which is more than the rest of us get paid for helping.

John
 

jayanthd

Joined Jul 4, 2015
945
What does the device do ? A frequency Counter ?

PIC12F1840 has 8 pins and if you are going to use USART then

RA0 and RA1 will be used for USART
RA2 is used for Capture
RA3 / MCLR pin can only be used for input or MCLR

RA4 and RA5 is used for what ? External Oscillator ?

Please provide more details. I might write a C code for you which can be easily ported to other PIC devices you mentioned easily.

Are you using it to make a tachometer for automobile ? Are you going to add XBee/Zigbee or Zigbee Wi-Fi to USART port and transmit vehicle speed data ?
 
Last edited:
Top