CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

High frequency PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

High frequency PWM
PostPosted: Mon Mar 15, 2021 11:34 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Mon Mar 15, 2021 11:41 am     Reply with quote

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. Smile
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Mon Mar 15, 2021 11:46 am     Reply with quote

Thank You for the help, I will review to learn about the changes you made.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group