View previous topic :: View next topic |
Author |
Message |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
how to make RESET after powerup ? |
Posted: Sat Mar 07, 2015 7:36 am |
|
|
Hello ,
my software requires RESET after power up...
I'm using PIC18F4525
How to make it ?
brdgs
-arto- |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Mar 07, 2015 9:16 am |
|
|
The compiler can get close to it with the 'reset_cpu' instruction, but this is not exactly the same as a power on reset. There are small differences in things like the actual clearing of the individual RAM locations in the chip. The differences are small on your chip (since it has a processor instruction designed to do this), but is larger on chips without this. |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sat Mar 07, 2015 9:30 am |
|
|
Ttelmah wrote: | The compiler can get close to it with the 'reset_cpu' instruction, but this is not exactly the same as a power on reset. There are small differences in things like the actual clearing of the individual RAM locations in the chip. The differences are small on your chip (since it has a processor instruction designed to do this), but is larger on chips without this. |
Thanks for your answer ...
but reset_cpu does not return it stop I've tried it ....
manual page 215 ... "this function never returns" ...
My program works OK if I after powerup press RESET button...
that's why I'm asking ...
all the best
-arto- |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Mar 07, 2015 9:49 am |
|
|
Er. Of course it won't return.
The CPU _resets_. It goes back to the start of the program.
Are you sure the processor is actually running?.
One thing that can happen, is that the CPU clock is not actually starting. The hardware reset then starts this. Software can't (since the chip is not running)....
You need to fix your hardware to get the chip to start.
Things would be:
1) Ensure the rise time of the power supply is fast enough.
2) Delay releasing MCLR till after the supply is good.
Last edited by Ttelmah on Sat Mar 07, 2015 9:53 am; edited 1 time in total |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sat Mar 07, 2015 9:51 am |
|
|
Ttelmah wrote: | Er. Of course it won't return.
The CPU _resets_. It goes back to the start of the program. |
no it does not ... it stop all nothing hapens after it |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Mar 07, 2015 9:54 am |
|
|
As you see I was still typing.
If the processor does not run, then it'll never get to the reset_cpu instruction. I suspect your chip is not actually _starting_. |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sat Mar 07, 2015 10:27 am |
|
|
Ttelmah wrote: | As you see I was still typing.
If the processor does not run, then it'll never get to the reset_cpu instruction. I suspect your chip is not actually _starting_. |
Thanks I will check my power on hardware ...
-arto- |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Mar 07, 2015 12:18 pm |
|
|
The classic reason for a chip that will start with a hardware reset after power is applied, would be the crystal not starting. Slow power rise can give this.
There is a maximum rise time for the supply for the internal reset to work. You can slightly improve things by putting a bias resistor across the crystal (perhaps 1M5R across the chip terminals). Adding your own circuit to hold MCLR low till a short period after the supply is stable.
Generally neither is necessary if the power to the chip does rise at a reasonable rate. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Mar 07, 2015 2:15 pm |
|
|
The other classic reasons are
1) program was compiled in 'debug' mode instead of 'release'
2) ICD or programmer still connected to PIC
3) faulty xtal/caps/PCB layout whisker/etc.
Jay |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sun Mar 08, 2015 5:49 am |
|
|
Ttelmah wrote: | As you see I was still typing.
If the processor does not run, then it'll never get to the reset_cpu instruction. I suspect your chip is not actually _starting_. |
This works :
Code: | #include<18F4525.h>
reset_cpu(); |
program starts OK
My error was to write reset_cpu(); function to be very first in main()
function ...
Lot of thanks for your good advices!
all the best
-arto- |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Mar 08, 2015 11:56 am |
|
|
What you are doing now, does not affect the code at all.
The instruction at this point will not actually generate any code at all...
You have changed something else (fuses or something similar), which is now making your code work. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 08, 2015 1:24 pm |
|
|
Quote: |
My error was to write reset_cpu(); function to be very first in main()
|
I think he was doing this, as he describes above:
Code: |
#include<18F4525.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
void main()
{
reset_cpu();
.
.
.
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Mar 08, 2015 3:06 pm |
|
|
Absolutely, which can obviously never work.
However the 'new' location does nothing. If his code runs with this, it'd run without the instruction just the same. The compiler generates no code at all for a reset_cpu instruction placed at the top of the file like this.
He has fiddled since his original problem (which we still don't know what it was), and now the chip is running, and he thinks it is this added instruction that has made it work (which it isn't)..... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 08, 2015 3:28 pm |
|
|
Quote: | He has fiddled since his original problem (which we still don't know what it was)
|
I don't think so. I think the only problem he ever had was placing
reset_cpu() at the beginning of main(). I think he thought it "returned"
after executing, and continued code execution in main().
You think he fiddled with fuses or something. I think he has a
fundamental mis-understanding of what reset_cpu() does, and what
the PIC does when it gets reset. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Mar 09, 2015 1:42 am |
|
|
He started saying his processor 'required reset after power-up'.
He said the chip worked if he pressed the reset button.
We looked at the classic 'reasons' for this (slow power rise (me), so the clock was not starting, and also things like ICD connections (Temtronic)).
He now says the chip is running with reset_cpu at the top as shown, which as you, I, and a lot of other posters know, does absolutely nothing. The compiler does not generate any code at all for the instruction placed there, so the chip would have worked just as well without the instruction at all. |
|
|
|