PWM for PIC16f877A

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PWM for PIC16f877A

Postby TeoYX » Thu Mar 01, 2012 8:55 am

Hi all,


I am using PIC16f877A to control 2 PWM outputs, which is RC1 and RC2. Below are the sample program for both PWM:

***************************************************************************************************************************************************
#define fanA RC1
#define fanB RC2

CCP2CON = 0b00001100; //PWM Mode

//PWM frequecy set as 4.88KHz
PR2 = 0xFF; //PWM Period Setting
T2CON = 0b00000101; //Timer2 On, prescale 4

//High Speed
CCPR1L = 255;
delay(5000);

fanA=1;

CCP1CON = 0b00001100; //PWM Mode

//PWM frequecy set as 4.88KHz
PR2 = 0xFF; //PWM Period Setting
T2CON = 0b00000101; //Timer2 On, prescale 4

//High Speed
CCPR2L = 255;
delay(5000);

fanB=1;

***************************************************************************************************************************************************

Here is the connection for the fanA and fanB
PWM Output Connection.JPG
PWM Output Connection.JPG (4.32 KiB) Viewed 3476 times


PWM Output Connection.JPG
PWM Output Connection.JPG (4.32 KiB) Viewed 3476 times


I measured the voltage output from RC1 and RC2 only get 0.05V only with 255. Is the 255 maximum value for the PWM? Don't it should be output 5V?

Please advice. Thanks a lot.
Attachments
PWM Output Connection 2.JPG
PWM Output Connection 2.JPG (3.12 KiB) Viewed 3476 times
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm

Re: PWM for PIC16f877A

Postby robosang » Fri Mar 02, 2012 10:39 pm

How about TRISC?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: PWM for PIC16f877A

Postby TeoYX » Sat Mar 03, 2012 10:05 am

TRISC = 0b11011001; where RC1 and RC2 are set to be output.
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm

Re: PWM for PIC16f877A

Postby robosang » Mon Mar 05, 2012 3:27 pm

Can you verify the code and hardware at least can execute program? Have you load the program in to PIC (sorry to ask, but many beginner din load the code) :mrgreen:
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: PWM for PIC16f877A

Postby ABSF » Tue Mar 06, 2012 9:59 am

TeoYX WROTE:I measured the voltage output from RC1 and RC2 only get 0.05V only with 255. Is the 255 maximum value for the PWM? Don't it should be output 5V?


50mV is not enough to make the transistor conduct. What is the voltage at the Collector to Ground?
Something is wrong with your program. Did you try with the sample code from cytron that is used to operate DC motors?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PWM for PIC16f877A

Postby TeoYX » Tue Mar 13, 2012 12:40 am

Problem solved. There is circuit connection problem. Haha. Thanks a lot for your reply. Thanks...
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 1 guest