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

Problems with two PWMs @ PIC16F877

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



Joined: 09 Feb 2009
Posts: 6

View user's profile Send private message

Problems with two PWMs @ PIC16F877
PostPosted: Mon Feb 09, 2009 9:43 am     Reply with quote

Hello everybody!
I'm new here and this is my first problem:

I want to generate two PWM signals with my PIC16F877. Therefore I use the following code. To check the PWM signals (CCP1 and CCP2) I have connected them with two LEDs. CCP1 works fine, CCP2 however stays low (LED does not shine).

Is there a problem with my code or maybe with the PIC??

Thanks
doke

Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

void main()
{
 unsigned char   dc ;
 setup_ccp1(CCP_PWM);                           // set mode to PWM
 setup_ccp2(CCP_PWM);
 setup_timer_2(T2_DIV_BY_16, 249, 1);           // set prescale, period and postscale
                                                // cycle time = (1/clock)*4*t2div*(period+1)
                                                // period 249 => 250 Hz

        for(;;)
                {
                for(dc = 10 ; dc < 249 ; dc++)
                        {
                        set_pwm1_duty(dc);      // set the duty cycle (0..period)
                        set_pwm2_duty(dc);
                        delay_ms (3);                       
                        }
                       
                for(dc = 249 ; dc > 10 ; dc--)
                        {
                        set_pwm1_duty(dc);
                        set_pwm2_duty(dc);
                        delay_ms (3);                       
                        }                     
                }
}
Ttelmah
Guest







PostPosted: Mon Feb 09, 2009 10:13 am     Reply with quote

Start by proving if it is the PIC.
Change your oscillator fuse to XT (HS, turns up the oscillator gain, and is really only meant for crystals > 4MHz), then run something really simple like:
Code:

#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

void main() {
    while (TRUE) {
      output_high(PIN_C1);
      delay_us(50);
      output_low(PIN_C1);
      delay_us(50);
   }
}

Triple check the actual connection. If the PWM2 pin (C1), doesn't light the LED now, you have proved you have a PIC problem.
Presumably you have got current limiting resistors to the PIC pins?. Otherwise you are overloading them....

Best Wishes
doke



Joined: 09 Feb 2009
Posts: 6

View user's profile Send private message

PostPosted: Tue Feb 10, 2009 11:04 am     Reply with quote

Thank you for your answer Ttelmah.

It tried the following code and only the LED at the RC2/CCP1 pin was blinking, no signal at RC1/T1OSI/CCP2 Sad

Code:
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

void main() {
    while (TRUE) {
      output_high(PIN_C1);
      output_low(PIN_C2);
      delay_ms(50);
     
      output_low(PIN_C1);
      output_high(PIN_C2);
      delay_ms(50);     
   }
}
Ttelmah
Guest







PostPosted: Tue Feb 10, 2009 11:27 am     Reply with quote

I'm afraid you have your answer... :(
Try unplugging your PIC, and checking with an ohmeter, the resistance of the RC1 pin to ground. It could be as simple as an almost invisible solder 'whisker' shorting the pin to ground. PICs are at times remarkably rugged, and unless you have been doing things with high voltages etc., round it, it is pretty uncommon to kill a pin.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 10, 2009 1:43 pm     Reply with quote

What if the LED is installed backwards ? Or the series resistor is too
low or too high in value ? (It should be about 220 to 470 ohms).

Check those things just to be sure.
doke



Joined: 09 Feb 2009
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 15, 2009 12:18 pm     Reply with quote

I'm afraid, the PIC is dead. I try to get another one, maybe then it works...
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