Do PICs goto sleep?


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

    Default Do PICs goto sleep?

    I have a small developmement which uses a PIC18F2550 (for later USB integration). At the moment, it takes 3 inputs from an RF module and depending on what button is pushed on the fob, jumps to a certain routine.

    The only problem is that it works for about a minute, then doesn't.

    If there is no activity, does the PIC goto sleep as such. I haven't come across this before if it does !!


    Here is my code:

    Code:
    Clear
    Define OSC 20          
    'Define LOADER_USED 1
    CMCON = 7 'disable comparators
    
    ' -----[ I/O Definition ]-----------------------------------------
    
    TRISA = %11111111	' Set PORTA to all input
    TRISB = %10000001   ' Set PORTB (0)INPUT (1-5)OUTPUTS
    TRISC = %11111111	' Set PORTC to all input
    PORTB = 0
    
    
    ' ----- System Outputs -----
    Red     VAR PORTB.1     ' All LEDs connected
                            ' between RC pins and
                            ' ground via resistor
                            
    ' ----- System Inputs -----
    SW1         Var PORTC.0
    SW2         Var PORTC.1
    SW3         Var PORTC.2
    
    
    ' -----[ Variable Definitions ]-----------------------------------
    Loop        Var Byte
    MaskSwitch  Var Byte
    
    Gosub Ready
    
    ' ************************************************************
    ' *                   Main Program Section                   *
    ' ************************************************************
    
    Main:
        MaskSwitch=PORTC & $07
            Select Case MaskSwitch
              Case 1 '%00000001 or SW1
                Gosub Procedure_SW1
    
              Case 2 '%00000010 or SW2
                Gosub Procedure_SW2
    
              Case 4 '%00000100 or SW3
                Gosub Procedure_SW3
        End Select
    Goto Main
    
    
    Ready:
        For Loop = 1 to 5
            Red = 1
            Pause 50
            Red = 0
            Pause 50
        Next Loop
    Return
    
    
    Procedure_SW1:
        Pause 10000 ' 20 second delay
        For Loop = 1 to 5
            Red = 1
            Pause 100
            Red = 0
            Pause 100
        Next Loop
    Return
    
    Procedure_SW2:
        red = 1
        pause 5000
        red = 0
    Return
    
    Procedure_SW3:
        for loop = 1 to 5
            red = 1
            pause 125
            red = 0
            pause 250
            red = 1
            pause 125
            red = 0
            pause 250
        next loop
    Return
    If you disconnect the power and then straight away reconnect, its still in a locked state. You have to remove power, wait about 8 seconds and then reconnect and all is fine, for a little while anyway! Most strange.

    Thank you

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Default

    I've never heard of any PICs going to sleep without beeing told so(they're just like kids ... and me), however i've never used this particular one. My guess is that your RF module gives out combinations that won't get caught by your SELECT CASE statement(0,3,5,6,7). Easily checked by adding CASE ELSE

    /Ingvar

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


    Did you find this post helpful? Yes | No

    Default

    Its not the RF module as the program works fine for the first minute or so.

    Also, all the hybrid RF module does is output a HIGH or a LOW on three ports which are fed into the PIC. So all the PIC is reading is a 1 or a 0.

    Any other suggestions,

    Steve

  4. #4
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    Is MaskSwitch ending up outside your parameters? What happens if you add a case else statement?

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


    Did you find this post helpful? Yes | No

    Default

    Hmm, got me thinking now.

    If i only wanted to look at RC0 , RC1 & RC2, i have now changed the TRISC to read:

    Code:
    TRISC = %00000111	' Set PORTC (0-2 input) rest Outputs
    Is this correct?

    Also, would any change need to be done for this line? What does the $07 mean?

    Code:
    MaskSwitch=PORTC & $07
    What would you suggest i put in the CASE ELSE statement. A return back to Main? It may be worth puttin in this statement to capture any other event.

    Thank you.

  6. #6
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    Actually I was going to suggest an output of some kind, maybe an led. If MaskSwitch gets outside of your parameters in someway you could effectively end up in a main ... goto main loop.

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


    Did you find this post helpful? Yes | No

    Default

    OK, I've added the following

    Code:
    Main:
        MaskSwitch=PORTC & $07
            Select Case MaskSwitch
              Case 1 '%00000001 or SW1
                Gosub Procedure_SW1
    
              Case 2 '%00000010 or SW2
                Gosub Procedure_SW2
    
              Case 4 '%00000100 or SW3
                Gosub Procedure_SW3
              Case Else
                Gosub Error
        End Select
    Goto Main
    
    Error:
        For loop = 1 to 5
            Red = 1
            Pause 100
            Red = 0
            Pause 100
        Next Loop
    Return
    Now the LED is flashing all the time, so i presume the CASE ELSE is true, which i guess means something else is happening.

    I think it may be due to the following:

    Code:
    MaskSwitch=PORTC & $07
    What does the $07 represent. Is this saying all of the PORTS on C. If so, what will it be if i want just PORTC.0, PORTC.1 and PORTC.2.

    Thank you, i think i'm getting there!!

  8. #8
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    I agree with IngVar,

    You have no way of knowing if the case statement is something other than 1,2,4. Put a default case in there with a blinking light....If that blinking light comes on... there is your problem.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

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


    Did you find this post helpful? Yes | No

    Default

    Dwayne,

    Is what i've done above your posting wrong then? If so, could you post the modification to the code you are suggesting.

    Many thanks.

  10. #10
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    $07 = %00000111

    Steve,
    If you push two buttons at the same time or if you're not using pull down/up resistors you end up with MaskSwitch = %00000110 which isn't an option.

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


    Did you find this post helpful? Yes | No

    Default

    Bugger, i think it might be due to no pull-down resistors.

    I've attahced my circuit, would this be the case?

    What values are recommended ?

    Hopefully that is the problem which is reasonably easy to fix.

    Regards,

    Steve
    Attached Images Attached Images  

  12. #12
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    Try 5K. Hopefully that fixes your problem.

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


    Did you find this post helpful? Yes | No

    Default

    The pull-down resistors didn't make any difference, the LED keeps in the 'error' flash routine. I didn't have and 5K, so i used a 2k2, would this still perform the task? If not i have 47k?

    However, i have inserted:

    Code:
    Main:
        MaskSwitch=PORTC & $07
            Select Case MaskSwitch
              Case 1 '%00000001 or SW1
                Gosub Procedure_SW1
    
              Case 2 '%00000010 or SW2
                Gosub Procedure_SW2
    
              Case 4 '%00000100 or SW3
                Gosub Procedure_SW3
              Case Else
                Goto Main
        End Select
    Goto Main
    Adding the Goto Main routine now seems to work.

    Although this is a work around, its still strange that some other signal is being received into the PIC which i would like to find.

    Cheers.

  14. #14
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    After looking at the HiRK-433 datasheet(assuming this is the one you use http://www.okwelectronics.com/datasheets/DS.0010-2.pdf ), i say that there is no need for pulldowns(or ups). Just make sure your JP1 and 2 are not linked. This would make the outputs latching, you want them to be momentary.

    /Ingvar

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


    Did you find this post helpful? Yes | No

    Default

    Yup, thats the exact one.

    Ok, i'll remove the pull-down resistors.

    It must be something else that is making the CASE ELSE statement true then.

    Cheers,

    Steve

  16. #16
    Join Date
    Aug 2005
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    When I am developing a project I always have a serial port available ,even if the project will not use it.Being able to check variables and ports is invaluable for debugging,versus debugging blind.

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


    Did you find this post helpful? Yes | No

    Default

    OK, i'm ready for a slap !!

    I failed to put a pull-up on the MCLR port. The thing is, i put it on my diagram, but failed to put it on the vero circuit.

    Thanks again to all those that helped. I did solve another a couple of issues at the same time. So all was not wasted.

    Regards,

    Steve

  18. #18
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Talking

    Here comes the ruler ......... Nah, that's to easy on somebody who forgot something as serious as a pullup on MCLR. It's time for Melanie to get into her leather outfit and teatch you real good, that way it'll surely never happen again. It might, however, make me want to forget all about resistors .... and their proper use

Similar Threads

  1. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. Problems with RC2 and RC3
    By Christopher4187 in forum General
    Replies: 11
    Last Post: - 29th May 2006, 17:19
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

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