Software Driven Reset Routine


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default Software Driven Reset Routine

    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:

    Code:
    ' 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.

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

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Code:
    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
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    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.

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

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,
    See: here
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

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

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. IC12F508 with Internal Oscillator and Software Reset
    By karan123 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd October 2009, 16:13
  2. Software reset
    By leonel in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 28th May 2008, 05:48
  3. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  4. How to reset the pic by software ?
    By Shamir in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th October 2006, 16:43
  5. Interrut Driven Oscillator
    By barkerben in forum Code Examples
    Replies: 5
    Last Post: - 2nd January 2005, 00:22

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts