Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

fast pwm

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
stef

Bascom Member



Joined: 11 Jan 2009
Posts: 2

blank.gif
PostPosted: Sun Jan 11, 2009 3:19 pm    Post subject: fast pwm Reply with quote

hello

I have a problem i was doing some small program in bascom with pwm.
Now my problem is that the output which i check with my osciloscope isn't equal to the one that i calculated. In the datasheet of the atmega32 i read there was something like a fast pwm how can i write it in bascom coes cant find a thing bout it in the help?

thx for help
Back to top
View user's profile
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 327
Location: Scotland

uk.gif
PostPosted: Sun Jan 11, 2009 7:10 pm    Post subject: Reply with quote

Bascom configures Timer1 in Phase Correct PWM when you specify PWM mode like this:
Code:
'Init Timer1 for PWM
'this does freq+phase correct PWM (WGM Mode 1)
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 256


To use Fast PWM, you can just do this:
Code:
'Init Timer1 for Phase Correct PWM
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 256

'now change mode to fast pwm (WGM Mode 5)
set TCCR1b.wgm12


That will basically double the output frequency relative to the default Phase Correct mode. You set the duty cycle using Pwm1a in the normal way.

It's similar for Timer0:
Code:
Config Timer0 = pwm , compare a pwm = clear down , compare b pwm = clear down , Prescale = 8

'change mode to Fast PWM (WGM mode 3)
set tccr0.wgm01


The PWM modes are documented in the Modes Of Operation section under Timer0/1 in the datasheet. Look for Waveform Generation Mode.

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5
Back to top
View user's profile
stef

Bascom Member



Joined: 11 Jan 2009
Posts: 2

blank.gif
PostPosted: Tue Jan 13, 2009 7:30 pm    Post subject: Reply with quote

hello

thanks this helps me aloth.
i apreciate your help and time Smile

grtz
Back to top
View user's profile
cowboyrx

Bascom Member



Joined: 05 Feb 2009
Posts: 6

blank.gif
PostPosted: Mon Feb 09, 2009 5:02 pm    Post subject: Reply with quote

Is there an example available or a possibility to generate a sine wave (with steps) using the fast PWM feature of mega48?
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue Feb 10, 2009 4:02 am    Post subject: Reply with quote

@ cowboyrx
You might get some ideas from:
http://evertdekker.com/Joomla/index.php?option=com_content&task=view&id=60&Itemid=99

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
cowboyrx

Bascom Member



Joined: 05 Feb 2009
Posts: 6

blank.gif
PostPosted: Tue Feb 10, 2009 3:38 pm    Post subject: Reply with quote

AdrianJ wrote:
@ cowboyrx
You might get some ideas from:
http://evertdekker.com/Joomla/index.php?option=com_content&task=view&id=60&Itemid=99

This is a fast pwm example provided by Atmel. Should work on mega48, but is in asm not Bascom. It compiles ok in AVR studio, but can't run it. It keeps saying 'waiting for PLL' Sad
http://www.avrfreaks.net/index.php?module=Freaks%20Tools&func=viewItem&item_id=498
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue Feb 10, 2009 10:39 pm    Post subject: Reply with quote

The AtTiny26 used in that example has an internal PLL capable of running at 64 MHz, and driving the timer1 counter for the fast PWM. AFAIK the AtMega48 does not have this PLL. You can still use PWM, but not with the high frequency clock source.
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Page 1 of 1

 
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