View previous topic :: View next topic |
Author |
Message |
beaker404
Joined: 24 Jul 2012 Posts: 163
|
High frequency PWM |
Posted: Mon Mar 15, 2021 11:34 am |
|
|
Looked over the forum and data sheets, not getting an answer.
18F23K22 @ 64MHz.
CCS 5.094
Looking at doing a PWM for an On Off Keying communication. Previously I have done it with a 2MHz oscillator chip and an RF detector. This works well. Space requirements are making me look for ways to trim part count.
So using a PWM output to generate the 2MHz signal seems plausible. Looking for a 50% duty cycle. I am not finding MHz level PWM discussions all are in the KHz range. 2MHz out of the range for the clock? I do not need any code actions that fast, just the hardware to generate a 2MHz PWM.
Took a run at the PWM setup:
Code: | setup_ccp1(CCP_PWM | CCP_USE_TIMER3_AND_TIMER4 ); // Set CCP1 as PWM using TIMER 4
setup_timer_4(T4_DIV_BY_1,8,1); // 2MHz Timer 4 rate
set_pwm1_duty/(50); // 50% duty cycle on PWM1
|
I am hoping someone who has done more PWM stuff can say whether this is doable or not. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19566
|
|
Posted: Mon Mar 15, 2021 11:41 am |
|
|
Code: |
setup_ccp1(CCP_PWM | CCP_USE_TIMER3_AND_TIMER4 ); // Set CCP1 as PWM using TIMER 4
setup_timer_4(T4_DIV_BY_1,7,1); // 2MHz Timer 4 rate
// /8 needs PR2=7
set_pwm1_duty/(16L); // 50% duty cycle on PWM1
//Now your clock gives full out at (PR2+1)*4 = 32. 50%=32/2=16
//Must be passed as an int16 (L).
|
Comments and changes inline. |
|
|
beaker404
Joined: 24 Jul 2012 Posts: 163
|
|
Posted: Mon Mar 15, 2021 11:46 am |
|
|
Thank You for the help, I will review to learn about the changes you made. |
|
|
|