CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how to make RESET after powerup ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

how to make RESET after powerup ?
PostPosted: Sat Mar 07, 2015 7:36 am     Reply with quote

Hello ,

my software requires RESET after power up...
I'm using PIC18F4525
How to make it ?

brdgs

-arto-
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Sat Mar 07, 2015 9:16 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 07, 2015 9:30 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Sat Mar 07, 2015 9:49 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 07, 2015 9:51 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Sat Mar 07, 2015 9:54 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 07, 2015 10:27 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Sat Mar 07, 2015 12:18 pm     Reply with quote

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: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 07, 2015 2:15 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 08, 2015 5:49 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Sun Mar 08, 2015 11:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 08, 2015 1:24 pm     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Sun Mar 08, 2015 3:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 08, 2015 3:28 pm     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Mar 09, 2015 1:42 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group