Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM in PIC18F452

Status
Not open for further replies.

xtrem7

New Member
hello,
sorry if my question is trivial, i am referring to app note AN843, AN889, AN900
i am having trouble understanding some part of it
it might be long to read, but i would really appreciate if you could go through it
the aim is to keep the voltage to hertz ratio output to the motor constant , the duty cycle determines the voltage, and the frequency determines the speed

to set the frequency of my output 3phase sine wave to 50Hz for example,
consider the following values:-
timer0_prescale=16
sampling frequency or #sine table entries =19
sine samples per cycle=(19-1)*2=36
instruction cycle= Fosc/4 = 5MHz
frequency scale= (instruction cycle/samples per cycle)/(timer0 prescale/4) = 32,744

the input at port AN1 is varied, say for example the ADC results give 200( C8 ), this value is loaded to the ADRESH register, which is then checked whether it lies in the range of 5Hz to 60Hz (in this case yes, scaling factor=4, 200/4=50)
it is then moved to port D, where it is frequency scaled and the results are transferred into temporary locations of timer0 register
34,722/200=174(AE)
this value is then subtracted from FFFF as timer0 reload value=FFFF - timer0
= 65362 (FF52) this is our new timer0 reload value
this upper byte and lower byte goes to the Timer0 registers
hence from our timer0 reload value (which is FFFF-FF52=174), we deduce that timer0 overflows when it counts up 174 counts
we know that our instructional cycle=1/(5MHz/prescalar)=3.2us
this implies that our interrupt is generated every 3.2*174=556.8us
frequency of our interrupt is 1/556.8us=1800Hz
from this frequency of our sine wave= interrupt freq/# of samples
=1800/36 = 50 Hz

this makes sense
but how do i know for a specific value of frequency [for eg in this case freq=200(50Hz)], what value the offset pointer will point to in the sine table, which is to be multiplied by that frequency and then loaded to the PWM register
and also how is the value to be loaded to the next PWM register calculated if i know the value of the PWM loaded to one PWM register
for eg, if 0x90 is loaded to CCPR1L (for PWM1), how do i know the value to be loaded in CCPR2L (for PWM2), timer1 (for PWM3)
i'd be very glad if you help me understand these concepts
i have been trying to understand it for some time, but unable to do so
your help will be very appreciated
thanks in advance
best regards
ryan
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top