Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Reset micro command

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 200
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Fri Jan 24, 2020 2:07 am    Post subject: Reset micro command Reply with quote

Top of the morning to you all.
This is bound to be a no brainer... Whats the code for resetting a micro? At the moment I'm starting the watchdog timer and letting it fail causing the micro to restart.

There's bound to be a more more elegant way of doing it i have come across yet

Thanks
Snow


(BASCOM-AVR version : 2.0.8.2 )
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Fri Jan 24, 2020 3:18 am    Post subject: Reply with quote

This will cause it to reboot but not the same as re-set pin

Code:

Goto &HC00
 
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Jan 24, 2020 4:01 am    Post subject: Reply with quote

I guess it depends upon what you need to accomplish.
I think the following is true, but I'm certainly open to hearing other thoughts.

For a "true" Reset, setting the Watchdog is the typical approach.
One could also use a "spare" I/O pin to trigger the Reset\ pin, perhaps through an RC combo.

Note that the above will:
Reset the micro.
Set all I/O pins to Input mode.
Reset the clock to the default, (Xmega, and possibly O-Series, but I haven't used the O-series yet).
Validate the Power On Reset control logic's signal to "start" the micro running again.
Trash variables.

If you just do a manual jump to the prog Org, it isn't clear to me that any of the above takes place, except for the SW manually reconfiguring the I/O pins, and re-initializing variables that you take the time to do within your SW.

JC
Back to top
View user's profile Visit poster's website
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 200
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Fri Jan 24, 2020 10:47 am    Post subject: Reply with quote

Hi JC.
I'm wanting to do a "Clean Boot Up" as if the power has been cycled basically.


Thanks
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Jan 24, 2020 8:14 pm    Post subject: Reply with quote

Paulvk wrote:
This will cause it to reboot but not the same as re-set pin
Code:

Goto &HC00
 

Reboot by chance maybe.
It may work if you use a bootloader, as it can jump to the bootloader-start then, if not it jumps into empty space or executes invalid opcode.
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Sat Jan 25, 2020 2:42 am    Post subject: Reply with quote

Quote:
I'm wanting to do a "Clean Boot Up" as if the power has been cycled basically.


Truly then, stick with the Watchdog timeout!

JC
Back to top
View user's profile Visit poster's website
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 200
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Sat Jan 25, 2020 11:51 pm    Post subject: Reply with quote

Thanks people for your feedback
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Sat Mar 14, 2020 6:24 pm    Post subject: Reply with quote

I must say that my experience with a watchdog reset versus a power cycle does not result in the same end.

For example, if I have corrupt variables (due to framesize, hwstack, etc) being overwritten, a watchdog reset doesn't fix it. Only a power cycle seems to.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Mar 15, 2020 12:47 am    Post subject: Reply with quote

KenHorse wrote:
I must say that my experience with a watchdog reset versus a power cycle does not result in the same end.

For example, if I have corrupt variables (due to framesize, hwstack, etc) being overwritten, a watchdog reset doesn't fix it. Only a power cycle seems to.

That's nonsense.
At startup a routine is executed, which clears SRam and sets the stack pointer, corrupt variables are gone then.
This startup happens even at soft reset via Goto 0, but sure as well at watchdog reset and power reset.
Defaults for all processor registers are however reset by watchdog and power reset only.
If you did experience anything different, then it's due to side effects, like hardware issues.
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Sun Mar 15, 2020 12:52 am    Post subject: Reply with quote

Only hardware (other than processor) that would be involved would be RS232 level shifter and +5 regulator and I've never heard of those needing a hard reset
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Mar 15, 2020 11:11 am    Post subject: Reply with quote

KenHorse wrote:
Only hardware (other than processor) that would be involved would be RS232 level shifter and +5 regulator and I've never heard of those needing a hard reset

Only because you did experience ambiguous problems which you've solved with a crowbar, it does not make your statement correct.
Be aware if you've used $NORAMCLEAR or $NOINIT without requirement, you did create the problem yourself.

You can check my statement with some simple code. At startup read the stack area, stack pointer and one timer register for example, print everything to UART.
Then recursively call 10 times a sub, which alters stack and stack pointer by saving return addresses, additional write to above timer register.
Activate the WD and wait for reset to happen, at restart you will notice stack pointer and stack area is reset to it's previous state and the timer register is at default too.

After you've found out my statement is correct, you don't need to confuse other readers anymore by doing generally false posts.

I do not doubt that your special circuit needed a power cycle, however I'd avoid voodoo and would check about the true culprit.
Btw., if you still have doubts for the controller it is a difference between WD-reset and hard reset, simply pull the controller's reset pin low.
If reset is not connected to anything else and pulling it leads to correct behavior of your circuit, then and only then you may have an odd behavior.
Microchip may be interested then.
Back to top
View user's profile
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Tue Mar 17, 2020 9:48 pm    Post subject: Reply with quote

In the many years I have used Bascom (and asm) and used it for a variety of boards and applications, I have never ever needed to reset the processor.
If that is needed, then there is a major problem with the software. Even in loops where is a danger of getting stuck, there is always a solution to overcome the situation. In my programing there is never a part to reset the processor. Bad handling of errors might lead to it. But again "bad programing". So, if you need to reset your processor, check your bad programing. The only time you need to reset, is when you reprogram flash memory. I have been through many different programing languages and the same rule applies, check your own faults.
Maybe a harsh remark, but true.

Best regards
Hubert
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Mar 17, 2020 10:05 pm    Post subject: Reply with quote

hgrueneis wrote:
In the many years I have used Bascom (and asm) and used it for a variety of boards and applications, I have never ever needed to reset the processor.
If that is needed, then there is a major problem with the software. Even in loops where is a danger of getting stuck, there is always a solution to overcome the situation. In my programing there is never a part to reset the processor. Bad handling of errors might lead to it. But again "bad programing". So, if you need to reset your processor, check your bad programing. The only time you need to reset, is when you reprogram flash memory. I have been through many different programing languages and the same rule applies, check your own faults.
Maybe a harsh remark, but true.

Best regards
Hubert


In my application, a reset of the processor (M2561) is necessary after 4K of new data is loaded into ERAM so it is read into SRAM for runtime and pointers are cleared.

I suppose there are other ways to accomplish that but I don't see a reset as the easiest way (smallest compiled code option as well) as any sort of cardinal sin
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Mar 18, 2020 12:02 am    Post subject: Reply with quote

KenHorse wrote:
I suppose there are other ways to accomplish that but I don't see a reset as the easiest way (smallest compiled code option as well) as any sort of cardinal sin

My son, you are forgiven for writing weird code, but you shalt suffer your sins for posting nonsense because you do not understand the code you wrote.
Quote:
For example, if I have corrupt variables (due to framesize, hwstack, etc) being overwritten, a watchdog reset doesn't fix it. Only a power cycle seems to.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum