Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Pwm on other port
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR
View previous topic :: View next topic  
Author Message
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 16, 2011 12:16 am    Post subject: Pwm on other port Reply with quote

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
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Fri Dec 16, 2011 4:48 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 30, 2011 2:57 am    Post subject: Reply with quote

Hi,

Thanks to reply.

Not solution for me on forum.
But i found chip for this fonction: PCA9685

I publish the example of use: http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=51187#51187

Thanks
Olivier
Back to top
View user's profile
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Fri Dec 30, 2011 6:01 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Dec 30, 2011 10:14 am    Post subject: Reply with quote

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
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 30, 2011 10:33 am    Post subject: Reply with quote

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
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Dec 30, 2011 10:50 am    Post subject: Reply with quote

"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
View user's profile
Ken_K

Bascom Member



Joined: 27 Jul 2008
Posts: 7
Location: Adelaide

australia.gif
PostPosted: Fri Dec 30, 2011 10:50 am    Post subject: Reply with quote

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
View user's profile
MAK3

Bascom Member



Joined: 24 Sep 2010
Posts: 449
Location: Germany

germany.gif
PostPosted: Fri Dec 30, 2011 10:59 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Dec 30, 2011 11:10 am    Post subject: Reply with quote

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
View user's profile
MAK3

Bascom Member



Joined: 24 Sep 2010
Posts: 449
Location: Germany

germany.gif
PostPosted: Fri Dec 30, 2011 11:40 am    Post subject: Reply with quote

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
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 30, 2011 12:21 pm    Post subject: Reply with quote

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
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 30, 2011 12:27 pm    Post subject: Reply with quote

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
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Dec 30, 2011 12:29 pm    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Dec 30, 2011 12:44 pm    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum