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 CCS Technical Support

2 pwm channel in ccs

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



Joined: 03 Jun 2022
Posts: 42

View user's profile Send private message

2 pwm channel in ccs
PostPosted: Mon Feb 10, 2025 6:24 am     Reply with quote

#include<18F67K22.h>
#device ADC=12
#use delay(internal=16000000)

#FUSES NOWDT
#FUSES WDT128
#FUSES NOXINST
#FUSES NOBROWNOUT
#FUSES NOMCLR

void main () {


setup_ccp10(CCP_PWM);
setup_timer_2(T2_DIV_BY_4, 255, 1); //approx 4khz

//setup_ccp1(CCP_PWM|CCP_PULSE_STEERING_D);

//setup_ccp1(CCP_USE_TIMER3_AND_TIMER4);
//setup_timer_4(T4_DIV_BY_4, 255, 1);







while(TRUE){



set_pwm10_duty(pwm_value);
delay_ms(50);

}
}

Hi everyone,I wanna use 2 pwm channels in different frequencies.in ccp 10(pin e2) I want approx 4khz(I can get the setting above) ;in eccp1 (pinc2) I wanna use sg90 but I couldn't figure it out how.sg90 uses 50 hz frequency.how can I change the timer source of eccp1 and how can I get 50 hz?
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 10, 2025 7:38 am     Reply with quote

Have to ask , what is the purpose of the 50 Hz ?
Can it just be a 50/50 square wave or do you have to change the duty cycle ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19730

View user's profile Send private message

PostPosted: Mon Feb 10, 2025 7:59 am     Reply with quote

You can't.....

The point about PWM, is to give relatively fast signals without involving
a lot of CPU work. On this chip, at 16MHz, the slowest you can get from a
PWM, is 16000000/(4*16*256) = 976.5625 Hz.
Now there are ways, not involving the PWM's.
So (for example), you can program a CCP in the toggle compare mode.
This then uses the 16bit timer3, 5 or 7 instead of the 8 bit even timer
modules. Potentially then gives 16000000/(4*8*65535^2)=3.915 Hz
minimum. However in this mode only gives a square wave.
So as Jay says. we need to know a lot more about what is needed...

Also, leam to use the code buttons when posting code please. .Smile
ilker07



Joined: 03 Jun 2022
Posts: 42

View user's profile Send private message

PostPosted: Tue Feb 11, 2025 12:07 am     Reply with quote

Ttelmah wrote:
You can't.....

The point about PWM, is to give relatively fast signals without involving
a lot of CPU work. On this chip, at 16MHz, the slowest you can get from a
PWM, is 16000000/(4*16*256) = 976.5625 Hz.
Now there are ways, not involving the PWM's.
So (for example), you can program a CCP in the toggle compare mode.
This then uses the 16bit timer3, 5 or 7 instead of the 8 bit even timer
modules. Potentially then gives 16000000/(4*8*65535^2)=3.915 Hz
minimum. However in this mode only gives a square wave.
So as Jay says. we need to know a lot more about what is needed...

Also, leam to use the code buttons when posting code please. .Smile



then do I have to use any timer for using SG90?
Ttelmah



Joined: 11 Mar 2010
Posts: 19730

View user's profile Send private message

PostPosted: Tue Feb 11, 2025 2:36 am     Reply with quote

SG90 is a simple servo. Look in the code library for a lot of examples of
code to drive servos.
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