What's a Microcontroller - Ch02Prj01 - Why does Red LED flicker after program e
Taylor
Posts: 3
I successfully completed project #1 at the end of chapter #2 of What's a Microcontroller.
I am left with two questions, as follow:
1. I am curious why the Red LED flickers·about every 2-3 seconds after the program ends?
To verify it is not a problem with the LED, I increased the time that the LED is on at the beginning of the program to 10 seconds, and·I also tried replacing the LED, but in both cases, the LED does not flicker while the program is running, only after it has ended. To prevent the LED from flickering, I added a DO...LOOP command around the final set of instructions to turn the LED RED, to prevent the program from ending, but this leave the controller in high power mode.
2. This bring up another question, "Can the microcontroller even go into low power mode·by executing·the end command, if an led is left on at the end of a·program?"
Here is the program , with some modifications which are commented out:
'Whats a microcontroller - Ch02Prj01_Countdown.bs2
'10 second countdown with red, yellow, green led
'Red/Green: Bicolor LED on P15, P14. Yellow: P13
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Byte
' Bi-Color LED Red for 10 seconds.
HIGH 15
LOW 14
LOW 13
PAUSE 10000···· ' LED does not Flicker
' Bi-Color LED Green...
LOW 15
HIGH 14
' ...while yellow LED flashes for 10 seconds.
FOR counter = 1 TO 10
· HIGH 13
· PAUSE 500
· LOW 13
· PAUSE 500
NEXT
' Bi-Color LED is Red and stays that way.
' DO··· ' The purpose of the do...loop is to prevent
······· ' the led from flickering when the program ends.
HIGH 15
LOW 14
' LOOP
' When the DO..LOOP is commented out,
' the RED LED flickers at the end of the program,
' with Or without the END command in the program.
END
Thanks,
Taylor
I am left with two questions, as follow:
1. I am curious why the Red LED flickers·about every 2-3 seconds after the program ends?
To verify it is not a problem with the LED, I increased the time that the LED is on at the beginning of the program to 10 seconds, and·I also tried replacing the LED, but in both cases, the LED does not flicker while the program is running, only after it has ended. To prevent the LED from flickering, I added a DO...LOOP command around the final set of instructions to turn the LED RED, to prevent the program from ending, but this leave the controller in high power mode.
2. This bring up another question, "Can the microcontroller even go into low power mode·by executing·the end command, if an led is left on at the end of a·program?"
Here is the program , with some modifications which are commented out:
'Whats a microcontroller - Ch02Prj01_Countdown.bs2
'10 second countdown with red, yellow, green led
'Red/Green: Bicolor LED on P15, P14. Yellow: P13
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Byte
' Bi-Color LED Red for 10 seconds.
HIGH 15
LOW 14
LOW 13
PAUSE 10000···· ' LED does not Flicker
' Bi-Color LED Green...
LOW 15
HIGH 14
' ...while yellow LED flashes for 10 seconds.
FOR counter = 1 TO 10
· HIGH 13
· PAUSE 500
· LOW 13
· PAUSE 500
NEXT
' Bi-Color LED is Red and stays that way.
' DO··· ' The purpose of the do...loop is to prevent
······· ' the led from flickering when the program ends.
HIGH 15
LOW 14
' LOOP
' When the DO..LOOP is commented out,
' the RED LED flickers at the end of the program,
' with Or without the END command in the program.
END
Thanks,
Taylor
Comments
"Just as with the SLEEP command, pins will retain their input or output settings after the BASIC Stamp is deactivated by END. For example, if the BASIC Stamp is powering an LED when END executes, the LED will stay lit after END, but every 2.3 seconds, there will be a visible wink of the LED as the output pin switches to the input direction for 18 ms. "
Heres more on the Sleep command.
Explanation
SLEEP allows the BASIC Stamp to turn itself off, then turn back on after a programmed duration. The length of SLEEP can range from 2.3 seconds to slightly over 18 hours. Power consumption is reduced to the amount described in the table above, assuming no loads are being driven. The resolution of the SLEEP instruction is 2.304 seconds. SLEEP rounds the specified number of seconds up to the nearest multiple of 2.304. For example, SLEEP 1 causes 2.3 seconds of sleep, while SLEEP 10 causes 11.52 seconds (5 x 2.304) of sleep.
Pins retain their previous I/O directions during SLEEP. However, outputs are interrupted every 2.3 seconds during SLEEP due to the way the chip keeps time. The alarm clock that wakes the BASIC Stamp up is called the watchdog timer. The watchdog is a resistor/capacitor oscillator built into the interpreter chip. During SLEEP, the chip periodically wakes up and adjusts a counter to determine how long it has been asleep. If it isn't time to wake up, the chip "hits the snooze bar" and goes back to sleep.
To ensure accuracy of SLEEP intervals, the BASIC Stamp periodically compares the watchdog timer to the more-accurate resonator time base. It calculates a correction factor that it uses during SLEEP. As a result, longer SLEEP intervals are accurate to approximately ±1 percent.
If your application is driving loads (sourcing or sinking current through output-high or output-low pins) during SLEEP, current will be interrupted for about 18 ms when the BASIC Stamp wakes up every 2.3 seconds. The reason is that the watchdog-timer reset that awakens the BASIC Stamp also causes all of the pins to switch to input mode for approximately 18 ms. When the interpreter firmware regains control of the processor, it restores the I/O directions dictated by your program.
If you plan to use END, NAP, or SLEEP in your programs, make sure that your loads can tolerate these periodic power outages. The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset glitch.
The answer to question two, is YES, the output states of the stamp will remain as you programmed them when your stamp goes to sleep.
So your low power mode will not be so "low power" if you allow your devices on your pins to draw current (leaving them turned on)
But keep in mind that for 18ms, every 2.3seconds durning sleep, all outputs will revert to inputs, causing ALL pins to go LOW for 18ms.
Post Edited (BPM) : 1/9/2006 6:11:39 AM GMT
You answered my questions very well.
You stated the following in regards to solving the issue of periodic power outages, "The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset glitch."
Could you further explain what you mean here, and how that would be simpler or different than the Do..LOOP that I used to prevent the flickering?
In an attempt to try what I thought you were suggesting, I connected the Bi-Color LED in series with a 470 ohm resistor between pins 14 and 15 on the HomeWork Board, as in the example of my previous post. Then I inserted one end of a 470 ohm resistor between the LED and the other 470 ohm resistor, and the other end of the resistor I connected alternately to Vdd or Vss. The result was that the LED got brighter or dimmer, but the flicker remained.
Your help is appreciated.
Thanks,
Taylor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
With your LED, you could do the same thing by connecting a big capacitor across the LED/resistor combination, and the capacitor would provide current during the glitch, but it is an idea that has problems. The LED takes too much current, and the Stamp outputs should not be made to drive a big capacitor. If you buffer the Stamp outputs with something like a CD4050 CMOS chip, with the LEDs on the output of the buffer, then the idea would work fine. Very small capacitors on the inputs of the buffers (thier self-capacitance even), would hold the state of the LED ON or OFF through the glitch, and you could still use SLEEP without the flicker. Of course STOP or DO:LOOP will work fine too, to stop the flicker, but that doesn't give you the relatively low power consumption of SLEEP.
Another solution is to use the BS2pe. The BS2pe has a special firmware that reduces the flicker interval down to 0.2 milliseconds, shorter by a factor of 100 from the 18 milliseconds of the other Stamps. So it is a lot less noticable, much easier to filter, and reduces the overall current in SLEEP.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
People like you make this such a great forum!
Taylor.
Or you could use a shiftregister if you have multiple LEDS. (something like a 74HC595) The shift register would remain in its set state even if the 18ms happens.
But all this is almost pointless, using the stamp in a low power mode while operating a LED or other device that draws a considerable amount of current.... Why put the stamp in a low power mode, the stamp already uses so little current to begin with.
Just make the stamp remain on using a DO LOOP.