View previous topic :: View next topic |
Author |
Message |
stef
Joined: 11 Jan 2009 Posts: 2
|
Posted: Sun Jan 11, 2009 3:19 pm Post subject: fast pwm |
|
|
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 |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Sun Jan 11, 2009 7:10 pm Post subject: |
|
|
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 |
|
|
stef
Joined: 11 Jan 2009 Posts: 2
|
Posted: Tue Jan 13, 2009 7:30 pm Post subject: |
|
|
hello
thanks this helps me aloth.
i apreciate your help and time
grtz |
|
Back to top |
|
|
cowboyrx
Joined: 05 Feb 2009 Posts: 6
|
Posted: Mon Feb 09, 2009 5:02 pm Post subject: |
|
|
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 |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
|
Back to top |
|
|
cowboyrx
Joined: 05 Feb 2009 Posts: 6
|
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Tue Feb 10, 2009 10:39 pm Post subject: |
|
|
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 |
|
|
|