View previous topic :: View next topic |
Author |
Message |
ilker07
Joined: 03 Jun 2022 Posts: 42
|
2 pwm channel in ccs |
Posted: Mon Feb 10, 2025 6:24 am |
|
|
#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
|
|
Posted: Mon Feb 10, 2025 7:38 am |
|
|
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
|
|
Posted: Mon Feb 10, 2025 7:59 am |
|
|
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. . |
|
 |
ilker07
Joined: 03 Jun 2022 Posts: 42
|
|
Posted: Tue Feb 11, 2025 12:07 am |
|
|
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. . |
then do I have to use any timer for using SG90? |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Tue Feb 11, 2025 2:36 am |
|
|
SG90 is a simple servo. Look in the code library for a lot of examples of
code to drive servos. |
|
 |
|