I'm working with a PIC16F818, though I've come to understand that setting up PWM in the registers is fairly universal.
First and foremost, I'm having a bit of trouble following what the variables mean in the PWM period formula:
PWM Period = [PR2 + 1] x 4 x TOSC x (TMR2 Prescale Value)
Questions on variables:
PR2: Is this just the decimal value of the binary bits in the PR2 register? (IE: b'00000111' = decimal 7 so the value of the term "PR2 + 1" = 8?
TOSC: Is this the value of the oscillator? IE: Internal Osc set to 4mhz means a TOSC value of 4 million? This seems much to high for the formula.
TMR2 Prescale Value: Okay, so the TMR2 prescale value is set by bits 1 and 0 in the TM2CON register. So if TM2CON bits one and zero are "01" this sets a prescale of 1:1. Does this mean I multiply by 1? If I set the prescaler to 1:16, does that mean this variable is "16" or "1/16"?
In the duty cycle formula, when the term "(CCPR1L:CCP1CON<5:4>)" is used, does this mean the term is the decimal value of the 10 bits from CCPR1L (8 MSB) and from CCP1CON bits 5 and 4 (2 LSB)?
My assumptions have to be wrong somewhere, because 1/Period (for frequency) would be extremely low for almost any setting.
Also, please see my attachment. I'm becoming familiar with the PICMultiCalc (thanks to SgtWooki for making me aware of it). At the bottom sections of the "PWM Calc" window labeled "Results." Is the "Duty Register" just the decimal value of CCPR1L and CCP1CON bits 5 and 4?
Thanks for the help!
First and foremost, I'm having a bit of trouble following what the variables mean in the PWM period formula:
PWM Period = [PR2 + 1] x 4 x TOSC x (TMR2 Prescale Value)
Questions on variables:
PR2: Is this just the decimal value of the binary bits in the PR2 register? (IE: b'00000111' = decimal 7 so the value of the term "PR2 + 1" = 8?
TOSC: Is this the value of the oscillator? IE: Internal Osc set to 4mhz means a TOSC value of 4 million? This seems much to high for the formula.
TMR2 Prescale Value: Okay, so the TMR2 prescale value is set by bits 1 and 0 in the TM2CON register. So if TM2CON bits one and zero are "01" this sets a prescale of 1:1. Does this mean I multiply by 1? If I set the prescaler to 1:16, does that mean this variable is "16" or "1/16"?
In the duty cycle formula, when the term "(CCPR1L:CCP1CON<5:4>)" is used, does this mean the term is the decimal value of the 10 bits from CCPR1L (8 MSB) and from CCP1CON bits 5 and 4 (2 LSB)?
My assumptions have to be wrong somewhere, because 1/Period (for frequency) would be extremely low for almost any setting.
Also, please see my attachment. I'm becoming familiar with the PICMultiCalc (thanks to SgtWooki for making me aware of it). At the bottom sections of the "PWM Calc" window labeled "Results." Is the "Duty Register" just the decimal value of CCPR1L and CCP1CON bits 5 and 4?
Thanks for the help!
Attachments
-
193.2 KB Views: 51