|
|
View previous topic :: View next topic |
Author |
Message |
coderchick Guest
|
2 PWMs, same frequency, different duty cycle? |
Posted: Thu Jun 05, 2008 5:50 pm |
|
|
Hello all!
I feel like I should be able to fix my issue with no problems, but my brain has seemed to have derailed and I can't get anywhere. I'm using an 18F6527 and part of the code I'm writing has to send out two PWMs on separate pins but with the same frequency. However, when one pin is high, the other must be low so that they alternate each other so that it looks something kind of like the below:
Code: |
__ __
__| |__| |__ <--PIN_G0 (CCP3)
__ __ __
|__| |__| <--PIN_G4(CCP5)
|
This is what my code looks like:
Code: |
#use delay(clock=5000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
void main()
{
int i;
setup_adc_ports(AN0_TO_AN3|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
setup_timer_2(T2_DIV_BY_4,154,2);
setup_ccp3(CCP_OFF);
setup_ccp5(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
while (TRUE)
{
setup_ccp3(CCP_PWM);
set_pwm3_duty(77);
setup_ccp5(CCP_PWM);
set_pwm5_duty(77);
}
}
|
With the way it's set up now, I can get both pins to have the same duty cycle, but what I want is to have the second one offset from the first. I've tried using CCP_PWM_H_L, CCP_PWM_L_H, CCP_PWM_H_H, CCP_PWM_L_L, and even the full and half bridges, but nothing seems to make it inverted from the first PWM. Anyone have any ideas on how to offset/invert my second PWM from the first?
KMoe
|
|
|
coderchick Guest
|
|
Posted: Thu Jun 05, 2008 5:55 pm |
|
|
Sorry, the square waveforms didn't turn out the way I thought they would. Hopefully you all don't need a visual to understand what it is I'm trying to do...
Fixed.
-- Forum Moderator |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Thu Jun 05, 2008 6:26 pm |
|
|
Try
code:
while (TRUE)
{
setup_ccp3(CCP_PWM);
set_pwm3_duty(77);
setup_ccp5(CCP_PWM);
set_pwm5_duty(128 - 77);
} |
|
|
coderchick Guest
|
|
Posted: Fri Jun 06, 2008 10:57 am |
|
|
It worked!! You're a genius, thanks a bunch!!
|
|
|
|
|
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
|