PDA

View Full Version : Software Driven Reset Routine



Tissy
- 10th April 2005, 14:40
As i am using the MCLR PORT as an input pin and also have an Interrupt Switch on RB.0. I would however, still like the option of having a Reset. I'm thinking of using the Interrupt switch as this option. At the moment it works as a menu selection type switch, push it once, it jumps to the next sequence, push it again, another sequence etc etc. I'm thinking that if the button is held down for 5 seconds then a RESET occurs.

The code i have is as follows:



' register and interrupt definition
'
CMCON = 7 ' Disable analog comparator on PORTA... not needed as now
OPTION_REG=0 ' enable pull-up resistor on PORTb
' Interrupt on falling edge of RB0

INTCON = %10010000 ' Enable RB0 interrupt

On Interrupt Goto ProcedureSwitcher

SoftwareReset:
Clear
@ clrf PCLATH
@ Goto 0
Return

ProcedureSwitcher:
Low PORTB.1 ' reset output to PORTB
Low PORTB.2
Low PORTB.3
Low PORTB.4
Low PORTB.5
DelayLoop=Delay ' to exit the delay loop
GetOut = 1 ' to get out of the entire PWM loops
PushHowManytimes=PushHowManytimes+1 ' Changing task
If PushHowManytimes=19 Then PushHowManytimes=1

InterruptHandler:
While ModeSwitch = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
If ModeSwitch=0 Then InterruptHandler
INTCON.1=0 ' reset RB0 interrupt flag
Resume ' Return to main program

Enable ' Enable interrupts after
' handler


Obviously thats not all of it, just the bits i think is relevant. The Interrupt Switch is known as ModeSwitch. I've tried putting this 5 second 'Button Held Down' Routine in the code, but having all sorts of problems. This is what i have come up with for the 5 Second Button Down Routine.



TimeOut VAR Byte

While Timeout < 100
While ModeSwicth = 0:Wend
Else
TimeOut = TimeOut + 1
Pause 50
EndIf
If TimeOut = 5000 Then Softwarereset
Wend


Am i right in thinking the code to do this needs to go in the InterruptHandler Routine, also have i got the 5 second pause bit right. I'm thinking not though !! I only want it to do the 5 second pause if the button is HELD down, if it is a single switch action then it performs normally.

Many Thanks,

Steve

NavMicroSystems
- 10th April 2005, 18:45
TimeOut VAR Byte

While Timeout < 100
While ModeSwicth = 0:Wend
Else
TimeOut = TimeOut + 1
Pause 50
EndIf
If TimeOut = 5000 Then Softwarereset
Wend


Steve,

TimeOut is a BYTE variable, how could it's value equal 5000?

Even if it was a WORD variable it would never reach a value of 5000 since the While...Wend Loop terminates as soon as TimeOut => 100

Tissy
- 10th April 2005, 23:53
OK, Think i have it, it seems to work, but then again it might just be a fluke. Is this the best way to do what i want ?? If Button is held down for 5 Seconds, Reset, else carry on.



TimeOut VAR Byte

InterruptHandler:
While ModeSwitch = 0 ' waiting until
Timeout = Timeout + 1
Pause 50
If Timeout = 100 Then SoftwareReset
WEnd ' push-button is release
Timeout = 0
pause 100 ' debounce time
If ModeSwitch=0 Then InterruptHandler
INTCON.1=0 ' reset RB0 interrupt flag
Resume


Also, does -


SoftwareReset:
Clear
@ clrf PCLATH
@ Goto 0
End

Perform the same action as if pulling the power and replacing it again, or does other things in the code need clearing also to make sure all is clear again?

Many thanks,

Steve

NavMicroSystems
- 11th April 2005, 00:11
Steve,
See: here (http://www.picbasic.co.uk/forum/showthread.php?t=1310&highlight=software+reset)

Tissy
- 11th April 2005, 00:36
Cheers, Ralph i did see that thread. The only reason i asked is that after the 'reset', the program was behaving strange on some of the outputs. During a normal power-up, ie power added to device, it performs a short LED PWM routine. Where an LED is illuminated for about 1 second at a preset brightness level, say 25%. After the 1 second, the LED goes out.

However, after the SoftwareReset routine has been activated, the same PWM routine is run, the LED is displayed at the 25% brightness, but instead of the then going out it stays on at full brightness, as if that PIN is now held High.

Thats why i asked if i was missing something. Does it actually perform a 'proper' reset as if using the MCLR PIN? Or do i need to do something else? I didn't want to use the addition of another Port Pin to "write" PortA.X = 0 to make a software reset if could do it in code.

Cheers,

Steve

NavMicroSystems
- 11th April 2005, 00:53
Steve,

as already mentioned, this is a "feature" of PWM
see PBP Manual section 5.61