PDA

View Full Version : Software reset - What am I doing wrong?



Christopher4187
- 18th August 2012, 15:26
For some reason, I need to reset the 18F4550 every single time whenever it's powered up. I don't understand why, perhaps it's because the 18F is on a demo board, but I've never had to do it before. Anyhow, accessing the reset button is a PITA so I want to use a software reset but nothing works like I want it to. I've tried using the power up timer but it doesn't seem to do anything.

I've also tried:

@ RESET
@ clrf PCLATH
@ goto 0
STKPTR=$FF

Some don't work and some keep the 18F in a continual reset loop. What am I doing wrong?

mackrackit
- 18th August 2012, 16:18
Can you post your code and configs along with what demo board you are using?

Christopher4187
- 18th August 2012, 16:25
I'm using the MCP2515 Demo boards from Microchip. I thought about that being an issue but it can't be because their code doesn't require a reset. If I was able to understand C I'd be able to solve this problem as they provide the source code to you. I'm pretty sure I copied the configs line-for-line from the source code. Anyhow, here it is:


DEFINE OSC 20
' ================================================== ============================
' CONFIGS
'================================================= ==============================


@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32768_2H
@ __CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_ON_4L & _XINST_OFF_4L

'================================================= =============================
' SETTINGS
' ================================================== ============================

TRISA = %00010110: PORTA = %00000000
TRISB = %00010001: PORTB = %00010000
TRISC = %00000000: PORTC = %00000001
TRISD = %00011100: PORTD = %00000000
TRISE = %00010000: PORTE = %00010111
ADCON0 = %00111100
ADCON1 = 15
ADRESH = %00000000
ADRESL = %00000000
CMCON = 7
SSPSTAT = %01100100
SSPCON1 = %00100001
BAUDCON = %00001111

mackrackit
- 18th August 2012, 17:29
I am not sure if this will help or if the CAN module needs it set, but try turning the ICPRT off.
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_ON_4L & _XINST_OFF_4L

Christopher4187
- 18th August 2012, 17:34
That gives me a code programming error at 0006. Not sure why but I'm trying to figure it out. The issue isn't with the CAN module, I've isolated the problem to the 18F4550.

mackrackit
- 18th August 2012, 17:39
Is your programmer erasing the device before loading the new code?

Christopher4187
- 18th August 2012, 17:54
That was part of my issue from the very beginning. I've used the 18F4550 for a number of projects and in all of them I used the ICSP. I've never had a problem. With these demo boards the erase always fails. I had to go into options -> more options -> erase -> and uncheck configuration/user ID and calibration. It still erases because when I hit the erase the program is wiped clean but I don't know what these two settings do.

You think this is my issue? I don't understand how the ICPRT setting affects the 18F powering up.

mackrackit
- 18th August 2012, 18:19
I have never had this problem before either and the 4550 or 2550 is what I use the most.

I normally have the MCLRE off and alway have the ICPRT off. The ICPRT is only available on the 44 pin packages and yes I use those too.

I have been reading section 25.9 of the data sheet trying to understand this.

mackrackit
- 18th August 2012, 18:29
Never mind.
I looked at the schematic for the demo board and ICPRT has to be ON.

Christopher4187
- 18th August 2012, 18:35
This is what Microchip uses for the config files. When their program is loaded, the power up sequence works fine so I don't think my issue is in the config file. If I can get the software reset to work correctly I would be golden.


#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config BORV = 3
#pragma config VREGEN = ON //USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
#pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = ON // Dedicated In-Circuit Debug/Programming
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CP2 = OFF
#pragma config CP3 = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF

EDIT: My configs do match Microchips, I just changed them today to try and rectify this issue.

Christopher4187
- 18th August 2012, 18:48
I need to clear my head and rethink this. I just turned off the power up timer and it's a little better. Removing the power-up timer no longer shuts down the CAN network but my program still doesn't work. This was a significant issue because if the 18F wasn't reset before the CAN network came on line, my car would be disabled (i.e. no throttle and all warning lights illuminated.)

I must have changed the settings along the way and forgot I did so. Let me do some more investigating as this issue is most likely caused by me. Thanks for turning on that proverbial light bulb in my head.

Christopher4187
- 18th August 2012, 18:52
And the second problem is solved! But, it creates another issue. I use a serial LCD and when I used the HSPLL, I couldn't get the LCD to work correctly. Perhaps someone reading this thread has encountered this before.

I'm using a 20mhz crystal. I use $4054 for the LCD speed. I defined my OSC as 20. If I use the HSPLL setting, what speed do I have to set the LCD at?

mackrackit
- 18th August 2012, 19:00
I did not notice that...
With the configs posted use
DEFINE OSC 48

Christopher4187
- 18th August 2012, 19:08
No dice. I tried using all of the prescalers from 4 to 48 but none work. By using the Define OSC 48, my program will not work. Any other adjustments you can think of?

Christopher4187
- 18th August 2012, 19:36
I just ran a loop increasing the communication speed of the LCD by 1 and then displaying the speed. When I was able to read the information on the LCD, that is the speed to use. It looks like something from $40E2 to $40F6 works. I need to do a little more testing to find out if there any differences in that range. I'm not sure if this the right way to go about solving this problem but it works......for now.