Quote:
|
Originally Posted by Kevin Watson
It's all done automatically in hardware. See page 154 of the data sheet. Here is example code that does what you need. It simulates a light dimmer by reading the voltage on analog input 1 and adjusts the LED brightness proportionally to the voltage read.
-Kevin
|
Just got back from the Philly regional, so I can dedicate some time back to this project now. I've spent some time looking at this stuff, and lemme see if I have the basic theory right...
-------
In one of the whitepapers or the example codes about timers, I read something about each timer having being slightly different and having its own idiosyncrasies... one of timer2's idiosyncrasies is this is the only timer that controls custom PWMs - if you set an output to a user pwm timed by the internal microchip hardware (i.e. no external oscillator or something like that), timer2 is what determines the timing. One period of the PWM signal is the amount of time it takes for timer2 to reach its rollover value and can be changed by either changing the duration of one timer2 clock tick or by changing the PR2, or
Timer2 Period Register, value.
The duty cycle of the PWM signal is programmed through the CCPR2L/CCPR3L byte, or the
Capture/Compare/PWM Register 1/2 Low Byte. When the timer value is below this register's value, the output pin is high, and when the timer value is above this register's value, the output pin is low. Thus, to create a pwm signal with a 50% duty cycle, you set the CCPRxL value to 1/2 the PR2 value, and to create a signal with a 25% duty cycle, you set the CCPRxL value to 1/4 the PR2 value.
----
Is this basic theory explanation right, or am I missing some part of it?
Also, what is the relationship between CCPRxL and CCPRxH? I didn't really understand that part of the datasheet.
And lastly, there is only CCPR1L, CCPR2L, and CCPR3L, so that means that the pic is capable of generating only three PWM signals (each with the same period, though - timer2's period), right? If this is the case, how do you select which PWM output on the edu uses which custom PWM signal, or does each custom PWM signal control only one PWM output pin? Also, the comments in the description of Mr. Watson's Initialize_LED_PWM function read:
Quote:
|
This function initializes the PIC18F8520 CCP2 & CCP3 modules to generate a free running 40KHz pulse train on the EDU-RC's PWM1 & PWM2 output pins. Once running, the duty cycle of the PWM outputs can the altered on-the-fly by updating the CCPR2L and CCPR3L registers.
|
This kinda implies that CCPR2L is bound to PWM1 and CCPR3L is bound to PWM2. What is CCPR1L used for then, or is the CCPR1L pwm not accessable on the edu?