Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Different frequencies

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Wed May 06, 2015 3:41 pm    Post subject: Different frequencies Reply with quote

Hi
I am using Atmega32, having OC1A and OC1B I want to generate 1khz at one channal while 100hz at other channal. 1kHz will be used to drive an voltage doubler for high side mosfet drive and 100hz for controlling pwm.
my question is it possible to do it with the said UC.

I can also use OC2 if needed.

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sat May 09, 2015 2:43 am    Post subject: Reply with quote

The Bascom samples show how to use a timer to generate any frequency, and certainly 1 Khz is possible. 100Hz is also possible to generate simultaeously on another output.

But its not so easy to generate a precise frequency and use the AVR hardware for PWM also. The big steps in the clock prescalers mean you can get for instance about 120 Hz at 8 Mhz clock frequency and still use PWM. Usually this does not matter for PWM, its pretty arbitrary what frequency you use , but it does depend on what your application needs.

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

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Sun May 10, 2015 6:19 pm    Post subject: Reply with quote

I am interested in generating 100 hz with duty cycle control from 0 to 100% would help me in doing so as I am not much conversant with timers.
regards
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Mon May 11, 2015 12:06 am    Post subject: Reply with quote

If you really MUST have the PWM frequency set precisely to 100Hz, then you need to use the Phase and Frequency Correct PWM mode, as described in the Atmel AtMega32 manual page 101. There are some limitations on the available resolution in this mode, depending also on the processor clock speed.

Read that first, and see if it will meet your needs.

If on the other hand you just selected 100Hz because it sounds like a nice number, then choose a frequency which can be generated using 256 counts ( at a suitable prescaler setting ) at your processor clock speed. Then many of the available PWM modes as built into Bascom will work.

_________________
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 -> BASCOM-AVR 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