Power Down? Please help a newbie...
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
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
Comments
- Sparks
Post Edited (Clint) : 6/28/2008 9:36:09 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Paul
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.
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
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?
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:
Thank you again for your help!
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Paul
Hopefully I can get this working soon. I appreciate your help!