View previous topic :: View next topic |
Author |
Message |
esa
Joined: 31 Jan 2008 Posts: 19
|
PIC18F2550 doesn't start each time on RESET button pressed |
Posted: Sun Dec 20, 2015 9:49 am |
|
|
Dear,
It took me a while before I found a solution and I want to share my experience.
1) The context :
1.1) I have a test Printed circuit Board where I can place a PIC16F877 or a PIC 18F2550.
1.2) I have a test program to check functionalities such as IIC, LCD, interrupts, timer ...
This way, I can test the same program on the same PCB with different controllers.
2) The problem :
When I press the RESET button, the PIC 18f2550 doesn't start every time (+/- 1 time on 3).
But, the PIC16F877 doesn't have a problem and starts every time.
3) What I did:
3.1) I first thought that it was a hardware issue and I changed the RESET circuit to avoid voltage spikes with the capacitor. That wasn't the problem.
3.2) I replaced the CTRL and the Crystal (changed from 20Mhz to 8Mhz) but still the same issue.
3.3) I created a simple BLINK program and there wasn't the problem.
So, the issue isn't related to the hardware. Good news.
3.4) I compared the USE flags in this simple BLINK program with the USE flags in my TEST program.
I found that the issue appears when I didn't set this flag :
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
remark : in the BLINK program the problem never appeared even if I didn't set this USE flag.
So, it is something related to a incompatibility with a functionality in the TEST program.
3.5) I place this FLAG in my TEST program.
When this flag is set then the program starts mostly every time. But if I insist a lot then I'm able to stuck the CTRL.
3.6) As this flag is related to the PORTB, I searched the functionalities on the PORTB.
I added "setup_adc(ADC_OFF);" but this wasn't the solution.
An interrupt is configured on PORT B2
Code: | enable_interrupts(INT_EXT2);
ext_int_edge( 2, H_TO_L);
|
And the pull-up is set on B2 : "port_b_pullups (0x100) ;"
If I suppress this line, then the program doesn't start any more.
So, I decided to suppress this line and to add a resistor instead.
After this, I'm not able to stuck the CTRL.
4)The solution
The solution is to add a pull-up resistor on port B2 and to use the FLAG "#FUSES NOPBADEN"
Summarizing :
If I place the resistor and I don't set this flag, then the CTRL never starts.
If I use soft Pull-up and without NOPBADEN : program stuck 1 on 3.
If I use soft Pull-up and with NOPBADEN : program stuck 1 on 10.
5) Questions:
I don't understand :
5.1) why I have this behaviour with the PIC18F2550 only.
5.2) why the program stuck if I place a resistor on B2 and I don't set "NOPBADEN"
5.3) why it stucks some time if I set a pull up resistor 'port_b_pullups (0x100) ) and I don't set "NOPBADEN"
Thank for your help.
Remark : I checked the same behaviour with several CCS compiler version. |
|
|
esa
Joined: 31 Jan 2008 Posts: 19
|
|
Posted: Sun Dec 20, 2015 10:20 am |
|
|
Ok, I answer to myself :
I didn't have defined a function for INT2
Code: | #INT_EXT2
void EXT2_isr(void)
{
}
|
If the INT routine isn't defined, then the progam stuck when there is an Interrupt.
And without "#FUSES NOPBADEN" there is always an interrupt after a RESET.
So it explain why it always stuck.
And with the SOFT pull-up, I suppose that the LEVEL high comes a little bit later than the INT triggered by the ANALOG input and the program can sometime start. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Dec 20, 2015 11:01 am |
|
|
without a schematic to go by, nobody can say if your RESET button is wired to do what you think it does .
If MCLR is enabled and you are using the push button in the approved manner - your code should not matter......
are you using MCLR per section 4.2 of the 18f2550 datasheet or not ? |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sun Dec 20, 2015 7:23 pm |
|
|
It sounds like the RESET is always working - it is what happens coming out of reset that was causing the confusion (at least that is how I am reading it). It "appears" that RESET is not working because it doesn't start up again, while in reality, RESET is working, it is just not showing signs of life after the RESET (because of the jump into the wild blue yonder with no ISR defined).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Mon Dec 21, 2015 2:13 am |
|
|
He has already posted that he realised what was wrong. Obviously found it soon after the original post, and immediately posted that he had.
Two things:
1) An interrupt without a handler.
2) Enabling an interrupt using a pin defined as analog.
Combined these result in the interrupt randomly triggering, which then results in the code randomly hanging on boot....
Lessons for everyone:
First never enable an interrupt without a handler (this is repeated many times here...).
Then second remember when using _any_ peripheral or pin, to ensure that every other device on the same pin is disabled.
The second here is 'less obvious' than it normally is, since in this case it is a fuse that configures all the pins of PortB for analog use.
Best Wishes |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Mon Dec 21, 2015 7:14 am |
|
|
One more possibility (not in this case obviously, but has bit me in the past): the oscillator not oscillating.
I based a product design on the CCS "reference" design they used for the CCS DSP development kit. Their kit has a ds33FJ processor with a 12MHz crystal. Turns out their kit won't always start (same symptom as OP asked about). The issue is the data sheet for the processor has a caveat that if the crystal is above a certain value (can't remember what that value is, but 12MHz is above it), then the oscillator isn't guaranteed to start when the PLL is enabled. ....That one took a while to find. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Mon Dec 21, 2015 8:07 am |
|
|
Quite a few of the DsPIC's actually require you to start on the internal oscillator, while others require this >8MHz. There are also some that do recommend a parallel resistor (the die has one, but it is too large, once the frequency goes over a few MHz). All designed to 'annoy'....
Best Wishes |
|
|
|