View previous topic :: View next topic |
Author |
Message |
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Dec 16, 2011 12:16 am Post subject: Pwm on other port |
|
|
Hi,
It's possible to create pwm on other port (pin) ?
Small explain for what:
I needed the dimming 18 leds, the value of dimming is same for all led, but i needed the change in real time.
Only one led is light in same time, every few second the led change.
Thanks to reply
Olivier |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Fri Dec 16, 2011 4:48 am Post subject: |
|
|
Doing a search for "pwm led" on the Bascom-AVR forum produces at least 26 results for this, many of which are relevant and worth reading for ideas. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Fri Dec 30, 2011 6:01 am Post subject: |
|
|
There is really no need for a separate chip.
Depending on the pwm frequency select a timer with the right prescale and max. count.
On timer start set or reset all led-port-pins(depending on the connection ...polarity of the leds).
For each "led on count" you can use a variable.
Then either with CASE or IF compare to the timer and if there is a timer > var. match...turn the pin off.
At a certain max. value, depending on desired frequency, restart the timer.
Just make sure that the current thru all of the leds (on at the same time) does not exceed the max. allowed current for the chip (electrical char.) mostly 200 mA.
Done
Hubert |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Dec 30, 2011 10:14 am Post subject: |
|
|
Hubert,
hgrueneis wrote: | On timer start set or reset all led-port-pins(depending on the connection ...polarity of the leds).
For each "led on count" you can use a variable.
Then either with CASE or IF compare to the timer and if there is a timer > var. match...turn the pin off.
At a certain max. value, depending on desired frequency, restart the timer. |
Your description is the one of a soft-pwm. However a standard approach with a reasonable pwm-rate, so there's no flickering, and with 18 portpins may easily bring the µC to it's knees.
Example: 8MHz µC-clock, pwm-rate 122Hz, ISR-rate 31.25kHz leaves 256 cycles for the ISR at 100 percent cpu-load, standard ISR-call takes 110 cycles, leaves max 146 cycles for the ISR-code. That's really not much for handling 18 pins. |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Dec 30, 2011 10:33 am Post subject: |
|
|
Hi,
thanks for your response.
I have try this solution, but is not easy (for me, i am not king of MCU), my problem is i needed the generate wait between each led.
For this solution i needed 'big' MCU (16 Output). The price of PCA + tiny 2K, is the same and i can drive more curent with PCA.
Best Regadrs
Olivier |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Dec 30, 2011 10:50 am Post subject: |
|
|
"Only one led is light in same time"
If your device is a low cost toy and your LEDs can take
a reverse voltage of 5V, all you will need is one PWM
output pin and 18 pins configured as output.
1 AVR chip.
18 LEDs.
1 resistor of 470 ohm.
The PWM output will have the 470 ohm resistor connected
to it and at the other end of the resistor will be connected
the 18 anodes (+) of the LEDs. Connect the each cathode (-)
of the LEDs to an individual pin of the AVR chip configured as
output. To turn off the LED set its output to "1". To turn on
the LED set its output to "0".
Never tested, but it should work.
Best regards,
Luciano |
|
Back to top |
|
|
Ken_K
Joined: 27 Jul 2008 Posts: 7 Location: Adelaide
|
Posted: Fri Dec 30, 2011 10:50 am Post subject: |
|
|
Idea: If only one led is on at any one time you could you could connect each of the LED anodes with its resistor to a separate output pin, all the cathodes could be joined together and attached to a single PWM output pin, when any LED anode pin is high (DC 5V) its led will light at the current determined by the pwm, all OFF leds will be reverse biased. Only one PWM output required, simply switch LEDs on and off.
Note: make certain the LEDs will stand 5 volts reverse bias, else fit diodes. It may suit better to have the PWM pin on all the anodes with resistors on the cathodes, a low on the LED cathode will turn it's LED ON.
Ken |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Fri Dec 30, 2011 10:59 am Post subject: |
|
|
Hi hobby,
why don't you use an ATXMEGA for that task ?
You can configure as many output channels as output compare register are available on the XMEGA.
For example an ATXMEGA128A1 provide 24 output compare channels or an ATXMEGA64D3 come with 18 output compare channels.
See also here: http://www.mcselec.com/index.php?option=com_content&task=view&id=306&Itemid=57
This is a one chip solution (beside the LED drivers).
MAK3 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Dec 30, 2011 11:10 am Post subject: |
|
|
MAK3 wrote: | why don't you use an ATXMEGA for that task ? |
Maybe because:
Quote: | The price of PCA + tiny 2K, is the same and i can drive more curent with PCA. |
The XMega, beside of these special capabilities is overkill here, more difficult to handle in regards of software and pcb-design.
Who wants a 100-pin monster, when a ATiny does the job ?
Your preference for XMegas is well known, but seen from the economic, say straight and easy side, it doesn't always make sense. |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Fri Dec 30, 2011 11:40 am Post subject: |
|
|
Hi MWS,
hobby is already using an ATMGEA324P in his posted example (a 44-pin Chip).
I can't see that he is using a ATTINY for that in his example.
The PCA9685 only provide 16 Channels so he nee two of this additional Chip to meet the 18 PWM's.
And my proposed ATXMEGA64D3 is a 64-Pin chip.
(I only checked at Farnell but the ATXMEGA64D3 is cheapter than ATMEGA324P there)
And single slope PWM on ATXMEGA is really easy with Bascom-AVR.
Mark have done a great job to make ATXMEGA programming that easy.
MAK3 |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Dec 30, 2011 12:21 pm Post subject: |
|
|
Hi,
The specification is change, sorry 2 LEDs in same time.
Thanks
Olivier
Luciano wrote: | "Only one led is light in same time"
If your device is a low cost toy and your LEDs can take
a reverse voltage of 5V, all you will need is one PWM
output pin and 18 pins configured as output.
1 AVR chip.
18 LEDs.
1 resistor of 470 ohm.
The PWM output will have the 470 ohm resistor connected
to it and at the other end of the resistor will be connected
the 18 anodes (+) of the LEDs. Connect the each cathode (-)
of the LEDs to an individual pin of the AVR chip configured as
output. To turn off the LED set its output to "1". To turn on
the LED set its output to "0".
Never tested, but it should work.
Best regards,
Luciano |
_________________ Thanks
Olivier |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Dec 30, 2011 12:27 pm Post subject: |
|
|
Hi Mak3,
Because the ATXMEGA128A1 is not low cost.
Farnell: 8Euro/10pc
With my final solution: PCA9685 2.13/10PC + ATTINT44 1.48/10pc = 3.61 Euro.
Thanks
Olivier
MAK3 wrote: | Hi hobby,
why don't you use an ATXMEGA for that task ?
You can configure as many output channels as output compare register are available on the XMEGA.
For example an ATXMEGA128A1 provide 24 output compare channels or an ATXMEGA64D3 come with 18 output compare channels.
See also here: http://www.mcselec.com/index.php?option=com_content&task=view&id=306&Itemid=57
This is a one chip solution (beside the LED drivers).
MAK3 |
_________________ Thanks
Olivier |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Dec 30, 2011 12:29 pm Post subject: |
|
|
Sorry,
The specification change only 16 channels.
Thanks
Olivier
MAK3 wrote: | Hi MWS,
hobby is already using an ATMGEA324P in his posted example (a 44-pin Chip).
I can't see that he is using a ATTINY for that in his example.
The PCA9685 only provide 16 Channels so he nee two of this additional Chip to meet the 18 PWM's.
And my proposed ATXMEGA64D3 is a 64-Pin chip.
(I only checked at Farnell but the ATXMEGA64D3 is cheapter than ATMEGA324P there)
And single slope PWM on ATXMEGA is really easy with Bascom-AVR.
Mark have done a great job to make ATXMEGA programming that easy.
MAK3 |
_________________ Thanks
Olivier |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Dec 30, 2011 12:44 pm Post subject: |
|
|
MAK,
MAK3 wrote: | I can't see that he is using a ATTINY for that in his example. |
Not in his example, but in his words, which I've quoted. It's not unusual to use a bigger µC for testing and scale down after to a cheaper unit.
Quote: | The PCA9685 only provide 16 Channels so he nee two of this additional Chip to meet the 18 PWM's. |
Yep, but still the Tiny/PCA combination is better
Quote: | ...can drive more curent with PCA |
and cheaper
Quote: | With my final solution: PCA9685 2.13/10PC + ATTINT44 1.48/10pc = 3.61 Euro. |
Quote: | Mark have done a great job to make ATXMEGA programming that easy. |
It may be a bit OT, but I did always wonder, if the huge efforts Mark did put in, not to forget your efforts, will finally pay out. And I mean this in a monetary sense. |
|
Back to top |
|
|
|