|
|
View previous topic :: View next topic |
Author |
Message |
desert Guest
|
16F877A dual PWM signals problem |
Posted: Fri Nov 28, 2008 10:12 am |
|
|
hi all,
I try to generate 2 PWM signals at CCP1 & CCP2 via this simple code:
Code: |
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
void main()
{
output_low(PIN_C1); // Set CCP2 output low
output_low(PIN_C2); // Set CCP1 output low
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
setup_timer_2(T2_DIV_BY_4, 124, 1); // 500 Hz
set_pwm1_duty(62); // 25% duty cycle on pin C2
set_pwm2_duty(62); // 50% duty cycle on pin C1
while(1); // Prevent PIC from going to sleep (Important !)
}
|
Checking with a scope I get the PWM I want at CCP2 but no luck on CCP1 no matter what I do.
Could this be due to a faulty PIC?
Is there a way to rule out this option?
Thanks for the help,
Moshe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 28, 2008 11:47 am |
|
|
Are there any external components connected to the CCP1 pin (Pin C2) ? |
|
|
desert Guest
|
|
Posted: Fri Nov 28, 2008 3:36 pm |
|
|
No, I disconnected everything so I can examine the micro controller alone.
it was originally connected to an H BRIDGE, but once it failed I started investigating.
the whole thing is mounted on a breadboard, but I sample the signal at the chip leg directly.
I find the chances of a hardware malfunction slim, but who knows...
any guesses or suggestions will be welcome.
thanks,
Moshe. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 28, 2008 3:49 pm |
|
|
Quote: | it was originally connected to an H BRIDGE, but once it failed |
Try a new PIC. |
|
|
desert Guest
|
|
Posted: Fri Nov 28, 2008 4:10 pm |
|
|
thanks for the help, I will try... |
|
|
mlkushan
Joined: 16 Nov 2008 Posts: 22 Location: Sri Lanka
|
Sample code to generate two 40KHz PWM signals |
Posted: Tue Dec 02, 2008 12:20 am |
|
|
Hi,
Check this code segment. This works fine. Hope this will be helpful to you also. This generates 40KHz PWM signals on both PIN_C1 and PIN_C2.
Thanks.
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
int16 pwm_duty = 50; //to get a higher resolution
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,24,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(pwm_duty);
set_pwm2_duty(pwm_duty);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(1);
}
|
_________________ Kushan Sharma
mlkushan@gmail.com |
|
|
|
|
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
|