Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Setting PWM values
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 26 June 2008, 23:10 PM    Post subject: Reply with quote

sturgessb wrote:
how is Register.ICR1 calculated? [I'm] confused.
That's why I've urged you several times to read AN-216. It gives a detailed description of the process including why/how a prescaler must be selected.

Also, I gave the formula for the Phase/Frequency Correct mode in a previous post, reproduced below.
Code:
icr = F_cpu / (2 * prescaler * F_pwm)

The key is to understand the role of the 'prescaler' element. This is necessary at lower frequencies to keep the ICR value less than 65536 which it must be to fit in a 16-bit register. With a prescaler of 1, the ICR value for 50Hz would need to be 368,640 - too large for a 16-bit register.

A prescaler value of at 6 or more must be used in order to reduce the ICR value to less than 65536. However, 6 is not one of the available choices which are (from the datasheet) 1, 8, 64, 256 and 1024. Choosing the smallest prescaler value that will work yields the maximum resolution (as explained in the application note), so a prescaler of 8 would be the best choice for 50Hz. Plugging that value in the equation above gives a result of 18,432 for ICR. That the ICR value is the same is not suprising because 50Hz is 1/8 of 400Hz and the timer is being clocked at 1/8 the rate in that case due to the use of 8 for the prescaler.

In any event, the duty cycle of the resulting waveform depends only on the ratio of OCR to ICR - the prescaler value is immaterial.
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 26 June 2008, 23:26 PM    Post subject: Reply with quote

I did read it, just maybe not understood it! Smile

Thanks for all your help Don. Got it working great using that, and its given the 100hz increase i was looking for!

Thanks

Ben
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Goto page Previous  1, 2
Page 2 of 2

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group