View previous topic :: View next topic |
Author |
Message |
Setna
Joined: 24 Jun 2008 Posts: 10
|
reset_cpu() question |
Posted: Wed Jan 07, 2009 12:37 pm |
|
|
Hey,
I was wondering if there is a way to have the PIC reset itself once about 5 seconds after the program starts. I believe the above function is what I need to use, but I keep getting infinite loops. Just in case the above isn't clear, I would like the PIC to follow this order:
1. Start when powered
2. Delay 5 seconds
3. Restart
4. Continue to Program Loop
I am using the PIC18F6722 Prototyping board with PCH version 4.068.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Wed Jan 07, 2009 2:50 pm |
|
|
Do you want to reset the PIC or reset your routine. I don't understand your application. It looks like you want to start, wait 5 seconds, then restart, which would repeat the 5 second delay infinitely. Is that what you want?
Or are you wanting on powerup to wait 5 seconds, then go into your main application? Need more info. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 07, 2009 2:55 pm |
|
|
Post a small test program that shows what you want to do.
Here is an example of a test program for the reset_cpu() function:
http://www.ccsinfo.com/forum/viewtopic.php?t=29718&start=8
The program that you post should be very short, just like that,
and it should compile without errors. |
|
![](templates/subSilver/images/spacer.gif) |
Setna
Joined: 24 Jun 2008 Posts: 10
|
Clarification |
Posted: Wed Jan 07, 2009 3:20 pm |
|
|
Here is a sample code that will run in an infinite loop. I would like the the reset to only occur once.
Code: |
int main()
{
int FirstPowerUp = 0;
delay_ms(5000);
if(FirstPowerUp==0)
{
//Would like the PIC to start up like normal, delay 5 seconds.
//When it starts for the second time, delay five seconds,
//and then go to the else statement where it will run a while loop.
FirstPowerUp = 1;
reset_cpu();
}
else()
{
while(TRUE)
{
//Run Program
}
}
}
|
I would like to reset the PIC because it is going to be remotely started along with a radio transmitter. The radio transmitter is modified so that the PIC can control each of the transmitters channels. The problem is that the transmitter loads with the wrong presets when started at the same time as the PIC. If i use the manual reset button after the transmitter completely powers up, it works. So I'm trying to automate this problem using the reset command.
Sorry if the explanation is not the best. Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Wed Jan 07, 2009 3:25 pm |
|
|
I think you want to remove the ().
You would be better off doing a DO loop instead. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
![](templates/subSilver/images/spacer.gif) |
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
Posted: Wed Jan 07, 2009 4:32 pm |
|
|
Take a look at the restart_cause() function. With it you should be able to determine the cause of the reset. If the reset was a POR then restart after 5 seconds if not then don't reset the cpu |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 07, 2009 4:51 pm |
|
|
Does the transmitter have its own initialization period that takes several
seconds ? I notice you already have 5 second delay at the start of the
PIC program. Maybe you just need to increase it to 10 seconds.
What you're proposing to do with the emulation of a hard reset, is
really just "papering over" the problem, whatever it is. You need to
find out what the real problem is, and fix it. It may well be that
it's as I proposed, that the transmitter isn't ready to take commands
until several seconds after power up (longer than 5 seconds).
Or, it may be that your PIC isn't starting up correctly from a power-on
start. Possibly that could be fixed by adding the BROWNOUT and PUT
fuses if you don't already have them. |
|
![](templates/subSilver/images/spacer.gif) |
Setna
Joined: 24 Jun 2008 Posts: 10
|
|
Posted: Wed Jan 07, 2009 5:07 pm |
|
|
I'm going to try using the restart_cause() function. Thanks Charlie U.
PCM Programmer,
If I'm understanding you correctly, you want me to have the PIC trigger the start of the transmitter. I have tried this using a switch. The PIC opens a gate that provides the transmitter with power and it starts. For some reason, the transmitter sometimes starts with the correct presets, but not always. However, if there both on, and I use the reset button it works.
I'm not sure if this will help, but the PIC is controlling 4 digital potentiometers. The regular potentiometers on the radio transmitter were cut off and replaced with these digital ones. The power for the potentiometers comes from the 5V power supply on the prototyping board.
Thanks again. |
|
![](templates/subSilver/images/spacer.gif) |
|