Program and circuit development continues on my current project and one aspect which I have working under test involves reading ambient light levels with an LDR via ReadADC and then modulating the LED brightness by varying the output via pwmout.
I only have a couple of LEDs with resistors on the PWMOUT pin for test.
In the final application I am looking to vary the supply for around 50 LEDs in total although no more than 30 or so would be on at any one time. Most of these will be controlled via MCP23016 I/O expanders.
I would appreciate some suggestions on the sort of FET or whatever to put on the PWMout pin to create the supply for the LEDS at the required current from the 5V supply.
An associated question relates to the best frequency to run pwm at. Have noted much discussion about the noise coming from different pwm frequencies but assume this relates to the devices being driven which would not apply to LEDs. Some seem to favour high pwm frequencies, some lower.
At the moment I have
pwmout 2,62,b0 - see code above
where b0 varies from 0 to 254 which keeps the values in the byte range. This means a 64KHz frequency at 16Mhz clock speed which is the final app clock speed (testing at 8Mhz at present)
I could of course slow this by using a word value but would prefer to keep this a byte value.
So the question is a multi part;
what device do I need on the end of the pwm out pin to;
1. handle the current
2. switch fast enough to maintain the pwm characteristics
3. allow the mcp23016 sink in comfort.
The mcp23016 has an internal clock of 1MHz and the digital I/O ports are TTL and latched.
Code:
' Vary LED Intensity depending on ambient brightness
ReadADC LDR,b0
If b0>b1 then let b1=b0-b1 ' test to see if READADC value changed.
elseif b1>b0 then let b1=b1-b0 ' ensure a positive value for b1
EndIf
If b1>20 then pwmout 2,62,b0 ' If READADC changed enough
b1=b0 ' store last LDR value used
Endif
In the final application I am looking to vary the supply for around 50 LEDs in total although no more than 30 or so would be on at any one time. Most of these will be controlled via MCP23016 I/O expanders.
I would appreciate some suggestions on the sort of FET or whatever to put on the PWMout pin to create the supply for the LEDS at the required current from the 5V supply.
An associated question relates to the best frequency to run pwm at. Have noted much discussion about the noise coming from different pwm frequencies but assume this relates to the devices being driven which would not apply to LEDs. Some seem to favour high pwm frequencies, some lower.
At the moment I have
pwmout 2,62,b0 - see code above
where b0 varies from 0 to 254 which keeps the values in the byte range. This means a 64KHz frequency at 16Mhz clock speed which is the final app clock speed (testing at 8Mhz at present)
I could of course slow this by using a word value but would prefer to keep this a byte value.
So the question is a multi part;
what device do I need on the end of the pwm out pin to;
1. handle the current
2. switch fast enough to maintain the pwm characteristics
3. allow the mcp23016 sink in comfort.
The mcp23016 has an internal clock of 1MHz and the digital I/O ports are TTL and latched.
Last edited: