LED at different level of intensity
Carlo
Posts: 23
Hi,
I am trying to program my BS2 to have various LED at different levels od brightness. I tried to use PWM but it will keep the LED on at any intensity but for a limited amount of time then the LED turns off. The only solution I found was to put the PWM command in a loop but the problem was that I couldn't do anything else while the loop was running.
I would like the LED which I can varry in brightness to remain at any given intensity as if it were just on or off.
I hope someone understands what I am trying to do and can offer a solution!
Thanks,
Carlo
I am trying to program my BS2 to have various LED at different levels od brightness. I tried to use PWM but it will keep the LED on at any intensity but for a limited amount of time then the LED turns off. The only solution I found was to put the PWM command in a loop but the problem was that I couldn't do anything else while the loop was running.
I would like the LED which I can varry in brightness to remain at any given intensity as if it were just on or off.
I hope someone understands what I am trying to do and can offer a solution!
Thanks,
Carlo
Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.sxvm.com
·
The PWMPAL offered by Parallax is one solution, for up to 4 channels of PWM:
http://www.parallax.com/detail.asp?product_id=28020
The PAK-5 co-processor is another solution, for up to 8 channels of PWM:
http://www.awce.com/pak5.htm
Regards,
Bruce Bates
I would just need 3 or 4 levels of brightness and I want to control it through outputs from the computer using SERIN. Possibly I would want to work with what I already have without needing to buy any new part.
Carlo
How about a digital pot ?
Can be driven direct from the stamp. Have not tried this myself, you may have to consider the power dissipated.
Regards
Alan
You may have to play around with the values to get 4 distinct brightnesses.
---edit---
By "off" I mean make the pin an input NOT low.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.sxvm.com
·
Put these together and you find pulse modulation for LED brightness doesn't work as you would first think. To a large degree your eye percives one intensity (the peak one).... it may see it flash, but the flash will be the same brightness. This is one reason multiplexed LED disdplays work so well.
Bean's suggestion of the multiple resistors is a safe a and sure way to go, since you have a limited number of intensities to light.
Under my professional hat I'm working on a project that requires calibratable light sources (red and blue), where I have to regulate the intensity of each color flash. To acheive that I have an I2C D2A driving a voltage to current converter, then to the LED. A micro controller (not a Stamp though a Stamp is smart enough and fast enough for this) uses a photo diode to read the intensity and control the LED drive to keep the intensity constant. Seems like a lot of work for little gain, but it makes sense in the overall application.
I would be very interested.
Chris Isaacson
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.sxvm.com
·
I posted code that describes in some detail this feature. I will look up the post, copy the section about brightness and repost.
Better yet, more than just the brightness portion, but how to use it.
;
[noparse][[/noparse]MAX7219 Operation]
;The 7219 must first be initialized. Initialization is done by sending serial
;data to the IC. Four 16 bit values sent will complete the initialization.
The initialization sets
1) decode mode
2) shutdown mode
3) scanlimit
4) intensity
;To send a 16 bit value load (p16 of 7219) is brought LOW, then each of 16 bits (msb 1st) is
;clocked into the IC, and load is then brought HIGH to complete the shifting
;of 16 bits into the device
;For each word sent to the IC, the most significant byte is·an address and the
;lower byte sets the option for each particular function.
;For the descriptions that follow, values will be shown as $Xx. The upper case x
;represents the upper nibble of a byte and the value is "don't care" and the lower case
;x represents some actual value
;DECODE MODE - Address $X9
;Options
;· $X0 = No decoding
;··$X1 = Decode digit 0 (BCD)
;··$XF = Decode digits 0-3 (BCD)
;··$FF = Decode digits 0-7 (BCD)
;Sending $09FF sets decode mode for all digits and instructs that the least
;sig nibble is BCD
The basic stamp code to do the above is:
DIRS = $000E············ 'pins 1 2 3 output,all other pins inputs
DOUT PIN 1·············· 'pin 1 of stamp to pin 1 of 7219
Load PIN 2·············· 'pin 2 of stamp to pin 12 of 7219
CLK PIN 3··············· 'pin 3 of stamp to pin 13 of 7219
;in my program there is a call to the subroutine DecodeMode:
DecodeMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$09FF\16]
· HIGH Load
· RETURN
; next you need to set the shutdown mode to active
;SHUTDOWN MODE - Address $XC
;Options·$X0 = Shutdown
;·$X1 = Normal Operation
;Sending $0C01 sets the IC for normal operation
;The BS2 code to do the above is:
;in my program there is a call to the subroutine ShutDownMode:
ShutDownMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0C01\16]
· HIGH Load
· RETURN
;Next you need to tell the 7219 how many digits are to be used.
;SCANLIMIT - Address $XB
;Options·$Xx where the least significant nibble sets the number of digits
;to enable. digit 0, x = 0. digits 0 & 1 x = 1. digits 0, 1, & 2 x = 2
;Sending $0B02 enbables digts 0, 1 & 2
;Sending $0B07 enables all 8 digits
;the BS2 code to do the above is:
;again, this is called with a subroutine
ScanLimit:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0B07\16]
· HIGH Load
· RETURN
;Next set the intensity of the the LED segments
;INTENSITY - Address $XA
;Options·$00 = minimum intensity
;$FF = maximum intensity
;See MAX7219 data sheet for resistor selection and current
;To set "medium" intensity ( I had a 47 k ohm resistor from pin 18 of the 7219 to vcc)
The bs2 code to do this is:
'Set intensity of LEDs
'LSNibble 0 = min intensity and F = max intensity
Intensity:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0A07\16]
· HIGH Load
· RETURN
Write back if you have questions.
Post Edited (KenM) : 3/4/2005 6:07:19 AM GMT
Sorry about that.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.sxvm.com
·
General-purpose I/O pins: each can sink 25 mA and source 20
mA. However, the total of all pins should not exceed 50 mA (sink)
and 40 mA (source) if using the internal 5-volt regulator. The total
per 8-pin groups (P0 – P7 or P8 – 15) should not exceed 50 mA
(sink) and 40 mA (source) if using an external 5-volt regulator.
Does this mean I can only plug 2 LEDs at 20mA to the stamp? Could someone please explain what this means?
Carlo
However,·that limitation is VERY easy to work around. Parallax documentation has addressed how to avoid the issue, but it is easier for me to simply tell you and post a schematic.
But please do read the parallax documention.
The transistor you can get at Radio Shaft
This configuration will consume about 200 uA or less from the stamp pin.
Depending on how many of these guys you put on the 5volt line, you might need to consider an external 5v regulator.
I don't use a stamp often these days, so I cannot tell you how much current the stamp on-board 5v regulator can handle.
I am sure some one else can chime in with that info.
This circuit assumes the LED forward voltage is 1.8, and the stamp output is a full 5 volts.
If so, the voltage on the anode of the LED (or transistor emitter) would be about 4.3 volts.
4.3 volts - 1.8 volts is 2.5 volts left over across the resistor.
2.5 volts / 125 ohms is 20 mA.
ken
Post Edited (KenM) : 3/4/2005 8:44:08 PM GMT
The Maxim 7219 can control 64 LED's at one time, WITH brightness control, and NO external circuitry (OK, maybe ONE resistor), so if you've got LOTS of LED's you may want to go that route.
You can control 8-LED's per '595 (or 4-LED's if you're using the two-resistor current-limit method). So dedicate one to the 4 'dimmable' LED's, and the other to the rest of your LED's.
Without looking at the datasheet, I believe what allan is refering to is that you can shift the contents of the register without affecting what the outputs are, then when your done shifting, you relatch the outputs to update based on what the internal registers contain, this avoids seeing the shifting action on the outputs.
Post Edited (Paul Baker) : 3/5/2005 1:11:33 AM GMT
here's an led calc i use for getting max brightness:
http://ourworld.compuserve.com/homepages/Bill_Bowden/led.htm
cheers
I bought a few 2N3904 transistors as Ken suggested me and I connected it to the circuit as in Ken's diagram but it doesn't seem to work. I don't know that much about transistors that's why I'm a bit stuck.
Would anyone be able to give me some suggestions?
Thanx
Carlo
Check the following:
Is the transistor ground connected to the same ground as the stamp?
As you look at the transistor with the flat side towards you, and the leads pointing down, from left to right the leads are emitter, base, collector
When you make the stamp pin go high, connect one lead of a voltmeter to ground, then what is the voltage on the base, emitter and collector?
What color is the LED you are trying to use, the circuit I posted is assuming you are using a "red" led that uses only about 1.8 volts forward biased.
Possibly misread the resistor value, and the one you are using is too large (value, not physical size).
Remove the resistor and measure the ohms.
k
Thank you
I connected the transistor as in the diagram with the base directly to the pin but it draws almost 30mA that is more than if I put only the LED. So I am back again to the original problem. I tried connecting a resistor to the base of the transistor that solves the problem, but at the same time it lets less current pass through the emmitter so it dims my LED. I hope you understand what my problem is!
Is there a formula to calculate the total resistance? or is there a way around this problem?
The resistor value in series with the LED needs to be increased.
·Do the following:
Basically, and LED uses a 'fixed' amount of voltage. ( In reality, the voltage across the LED will vary a little with the current through it, but lets not get into that now)
What ever voltage is 'left over' in your circuit, is used to select a resistor value that will set the current to some desired value.
Ex. There is a 5 volt circuit (4.3 in your case)
The LED uses 2.0 volts.
5 volts - 2 volts gives you 'left over' 3 volts.
3 volts divided by the desired current = the needed resistor value
I managed to solve all the problems I had thanks to you guys!!
I had one·other question: what is the maximum current can I draw from Vdd and Vss? I am using the BS2 educational board. Will the limit be the maximum current the transformer can output?
Thanks again!
Carlo
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
www.parallax.com
·