Shop OBEX P1 Docs P2 Docs Learn Events
Power Down? Please help a newbie... — Parallax Forums

Power Down? Please help a newbie...

ClintClint Posts: 95
edited 2008-06-30 20:29 in General Discussion
I've made something·that's basically equivalent·to the quadrature encoder input example in the SX/B help file (see attachment), except I'm using an optical encoder that needs 5volt power. Unfortunately I am new to microcontrollers and could use some help.

What I would like to do is have a simple momentary pushbutton that I can use to turn on and off this device. I want to use little or no power when off because this will be running on battery power. From both a hardware and software standpoint, how can I have this thing kill power to the LED display and encoder when a pushbutton is pressed?·I was thinking about using the SLEEP function somehow and using an output with a transister to power my components.

Does anyone have any examples of how this would be done? I am using an SX28AC/DP

Thank you for any help.

Post Edited (Clint) : 6/28/2008 2:52:38 AM GMT
564 x 549 - 34K

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-06-28 04:46
    Let me first ask if it is essential that you use a momentary push button. Is it? If not I think a simple push-on/push-off switch inline with the battery should work quite nicely. wink.gif

    - Sparks
  • ClintClint Posts: 95
    edited 2008-06-28 20:00
    Well, no it's not entirely essential I guess but I was also·also hoping to have the unit turn itself off if it's been inactive for too long.

    Post Edited (Clint) : 6/28/2008 9:36:09 PM GMT
  • VelocitVelocit Posts: 119
    edited 2008-06-28 23:15
    It sounds like you're on the right path. Depending on your power needs, I would either use a Darlington pair NPN transistor or an N-channel MOSFET to control a common ground to all components. Have the SX control the base/gate to that transistor/MOSFET. You can have the SX scan a momentary pushbutton through either an interrupt routine, or just have it check the button when it's not doing something else. If the button's been pressed, it can either wait for a little while or prepare to go to sleep. It wouldn't be too difficult to have it "timeout" and go to sleep either. Why don't you write a little psuedocode to define what you want the program to do? It sounds like most everything will be done in software for this project; the hardware will be trivial.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • ClintClint Posts: 95
    edited 2008-06-29 19:25
    Basically what I want to happen is:
    if pushbutton is pressed and held for x time, power down components (for example, make output to a transister go to 0) and go into sleep
    if there has not been a change in the encoder for x time, power down components and go into sleep
    if in sleep and pushbotton is pressed, come out of sleep and power up components

    It it is okay if the SX is reset when coming out of sleep. From the specs it looks like the components I am powering (encoder and display) will suck a maximum of about 200mA, most of which is from the display.

    Do you have any suggestion on what kind of transistor to use for powering these components? You're saying I should switch off a common ground from the encoder and display?

    Can someone explain how to use the sleep function using SX/B? I don't understand how it's used or how to have a pushbotton/input control it.
  • VelocitVelocit Posts: 119
    edited 2008-06-29 19:53
    To put the SX to sleep itself, all you need to do is use the "SLEEP" command. I've seen others put a few "nop" commands directly after, though I don't know the exact reasoning. To wake it up, you just need to configure a few registers:

    WKED_B = %1111_1110
    WKPND_B = 0               
    WKEN_B = %1111_1110        
    
    



    WKED_B specifies which edge triggers the wake up routine. 1's signify a falling edge and 0's signify a rising edge. In this example, RB.0 is set to look for a rising edge before waking up the SX. The WKPND_B register should be cleared before every time you put the SX to sleep. The WKEN_B register is what specifically enables the port B pins to wake up the chip when triggered. 0's enable the pins. Only RB.0 is enabled here.

    The 2N2222 transistor should work just fine for your needs, though something like a TIP110 might be more straightforward to implement.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • ClintClint Posts: 95
    edited 2008-06-29 22:44
    Thank you Paul. What is the "_" for in the lines "WKED_B = %1111_1110" and "WKEN_B = %1111_1110"?

    So if I connected a momentary, NO pushbutton with +5 to the RB.0 pin and used the following·code, I could put the SX into sleep by pushing the button and it·would wake up after getting a rising edge from RA.0?

    Pushbutton   VAR     RA.0 Yes          CON     1
     
    Start:
    WKED_B = %1111_1110
    WKPND_B = 0               
    WKEN_B = %1111_1110 
     
    Main: 
    IF Pushbutton=Yes THEN
       SLEEP
    ENDIF
    

    How could I modify this so that accidentally pushing the button without holding it for a period of time wont accidentally turn off the device? I was thinking of using a a pause·like this:

    IF Pushbutton=Yes THEN
       PAUSE 1500
       IF Pushbutton=Yes THEN
          SLEEP
       ENDIF
    ENDIF
    

    Thank you again for your help!
  • ClintClint Posts: 95
    edited 2008-06-29 23:10
    Velocit
  • VelocitVelocit Posts: 119
    edited 2008-06-29 23:59
    The 2N2222 in a TO-92 package is certainly smaller than the TIP110 in a TO-220 package. The main difference is that the TIP110 is a Darlington pair, or one transistor switching another; the advantage of such being high current gain. With the 2N2222 you'll need to calculate the values for the correct biasing resistors depending on supply voltage, anticipated current draw, etc.. The TIP110, on the other hand, can be used with only a 220 or 470 ohm resistor between its base and the I/O pin... mainly for the SX's protection.

    The underscore between the upper and lower bytes in my sample code is solely to make reading it easier. You can also place them where commas might go in large decimal numbers, such as "10_000."

    You could time the button presses as you did in your second to last post, or you could just use the PULSIN command. The next line of code would check the result of PULSIN, and if it's large enough, the SX would go to sleep.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • ClintClint Posts: 95
    edited 2008-06-30 03:04
    Thank you Paul, you've been incredibly helpful. I will pick up a few transistors and give this a shot.
  • ClintClint Posts: 95
    edited 2008-06-30 19:38
    Is there any problem using a TIP120 instead of a TIP110 for this? I went to RadioShack and that was all I could find. I don't have a good electronics store nearbye [noparse]:([/noparse]
  • VelocitVelocit Posts: 119
    edited 2008-06-30 20:01
    That should work fine. For the record, Mouser and Digi-key are usually the way to go when you need parts. Their prices are usually cheaper and their selection is much greater by far. The only downside is waiting for the parts to arrive.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • ClintClint Posts: 95
    edited 2008-06-30 20:29
    Thanks Paul. I have been using both for a while now. DigiKey has that pesky minimum order thing. I hate paying extra because I only had a few components! I prefer using Mouser, but either way the shipping cost and time sometimes makes heading to the local places less of a headache.

    Hopefully I can get this working soon. I appreciate your help!
Sign In or Register to comment.