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 support@ccsinfo.com

Help with PWM on PIC16F876 or 16F877

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 10, 2011 10:10 pm     Reply with quote

If something doesn't work, make a very simple test program that tests
only one thing. See if it works. For example, here is a program to
test PWM on the CCP1 pin. Test it, exactly as shown, with no changes.
Code:

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

//==========================
void main()
{
setup_timer_2(T2_DIV_BY_16, 255, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(128);    // 50% duty cycle

while(1);
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 6:29 am     Reply with quote

Have you got pullup resistors on your pushbuttons? And why not use Port B, which has internal ones?
CheAhMeD



Joined: 10 Apr 2011
Posts: 4
Location: Tunisie

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 6:32 am     Reply with quote

PCM programmer wrote:
If something doesn't work, make a very simple test program that tests
only one thing. See if it works. For example, here is a program to
test PWM on the CCP1 pin. Test it, exactly as shown, with no changes.
Code:

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

//==========================
void main()
{
setup_timer_2(T2_DIV_BY_16, 255, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(128);    // 50% duty cycle

while(1);



Hello PCM programmer and thank you for responding

I did exactly what you told me to do and still nothing on the CCP1 (PIN_C2) there is no signal :(
CheAhMeD



Joined: 10 Apr 2011
Posts: 4
Location: Tunisie

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 6:33 am     Reply with quote

John P wrote:
Have you got pullup resistors on your pushbuttons? And why not use Port B, which has internal ones?



Yes I did put resistors on both push buttons and the port B is for the LCD
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 11:48 pm     Reply with quote

Does the PIC do anything ? Have you ever made it blink an LED ?

If you have no PWM signal, it could be because:

1. You have the LVP fuse enabled while not needing it, and pin B3 is
not connected to ground with a pull-down resistor, and is floating.
This causes the PIC to lock-up when pin B3 floats to a high level.
Solution: Change it to NOLVP.

2. The PIC is not running, because the oscillator is not working, or the
PIC is held in reset because the MCLR pin doesn't have a pull-up resistor
on it, or the PIC doesn't have power or ground connected to it.

3. The CCP1 pin may be connected to a very low resistance load
which the output driver on the PIC's CCP1 pin can't handle, and
therefore you see no PWM signal. The pin is loaded down too much.
Solution: Disconnect the load (the motor, or whatever it is). See if
you now get a signal. If so, you need an external driver for the motor.
CheAhMeD



Joined: 10 Apr 2011
Posts: 4
Location: Tunisie

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 9:03 am     Reply with quote

PCM programmer wrote:
Does the PIC do anything ? Have you ever made it blink an LED ?

If you have no PWM signal, it could be because:

1. You have the LVP fuse enabled while not needing it, and pin B3 is
not connected to ground with a pull-down resistor, and is floating.
This causes the PIC to lock-up when pin B3 floats to a high level.
Solution: Change it to NOLVP.

2. The PIC is not running, because the oscillator is not working, or the
PIC is held in reset because the MCLR pin doesn't have a pull-up resistor
on it, or the PIC doesn't have power or ground connected to it.

3. The CCP1 pin may be connected to a very low resistance load
which the output driver on the PIC's CCP1 pin can't handle, and
therefore you see no PWM signal. The pin is loaded down too much.
Solution: Disconnect the load (the motor, or whatever it is). See if
you now get a signal. If so, you need an external driver for the motor.




Hello PCM programmer,

I tried the program in ISIS in this circuit



It's a simple schematic but it doesn't work the pin CCP1 (PIN C2) is always blue (LOW 0v)

I'm really confused
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