![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
pwm duty cycle getting wrong |
Posted: Thu Mar 15, 2007 11:58 pm |
|
|
Dear sir,
here i am using 16f684, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534
In this i am generating 100KHz freq. & 50% duty cycle,using PWM(timer2).
here i am getting T= 10 usec,freq=100Hz.this is correct.i checked on oscilloscope.
But i am not getting correct 50% duty cycle. i.e. 5.2 usec on & 4.8 off.
So, plz tell me what changes i have make in my source code.
Below is my source code....
#if defined(__PCM__)
#include <16F684.h>
#device ICD=TRUE
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOPROTECT,NOMCLR,NOCPD
void init_CPU();
void main()
{
OUTPUT_LOW(PIN_C5); // Set CCP1 output low
init_CPU();
while(TRUE)
{
}
}
#INT_TIMER2
void isr_TIMER2()
{
//OUTPUT_TOGGLE(PIN_C5);
//CLEAR_INTERRUPT(INT_TIMER2);
}
void init_CPU()
{
PORT_A_PULLUPS(FALSE);
SET_TRIS_A(0x0B);
SET_TRIS_C(0X10);
SETUP_OSCILLATOR(OSC_8MHZ);
SETUP_COMPARATOR(NC_NC_NC_NC); // Make comparator off
ENABLE_INTERRUPTS(GLOBAL);
ENABLE_INTERRUPTS(INT_TIMER2);
SETUP_CCP1(CCP_PWM); // Configure CCP1 as a PWM
SET_PWM1_DUTY(10); // 50% duty cycle ....2 LSB in (DC1B1 DC1B0) of CCP1CON register,
// The eight MSbs are found in CCPR1L.
SETUP_TIMER_2(T2_DIV_BY_1, 19, 1); // Setup for 100 KHz
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 16, 2007 11:50 am |
|
|
I don't have your PIC, but I tested it with vs. 3.249 on a 16F877A
and it is 50%. I also looked at the .LST file for your PIC and it looks
OK in terms of the PWM duty cycle setup. I think you may have a
scope problem or the PWM pin output may have a capacitive load on
it that changes the shape of the waveform. |
|
![](templates/subSilver/images/spacer.gif) |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
GOT SOLUTION FOR 16F684 PWM duty cycle |
Posted: Sat Mar 17, 2007 2:05 am |
|
|
Dear PCM Programmer,
Yesterday i was asked, question regarding PWM duty cycle getting wrong for 16f684 pic ic.
but, 2day i got got solution over it,
In my source code one statement is like this,
SETUP_CCP1(CCP_PWM);
so,if u replace this with following,
SETUP_CCP1(CCP_PWM_L_L);
you get exact 50% duty cycle...
One thing plz tell me sir,how will i get the explations of all definations which was defined in devices.h file.
i.e.
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
long CCP_1;
#byte CCP_1 = 0x13
#byte CCP_1_LOW= 0x13
#byte CCP_1_HIGH= 0x14
// The following should be used with the ECCP unit only (or these in)
#define CCP_PWM_H_H 0x0c
#define CCP_PWM_H_L 0x0d
#define CCP_PWM_L_H 0x0e
#define CCP_PWM_L_L 0x0f
#define CCP_PWM_FULL_BRIDGE 0x40
#define CCP_PWM_FULL_BRIDGE_REV 0xC0
#define CCP_PWM_HALF_BRIDGE 0x80
#define CCP_SHUTDOWN_ON_COMP1 0x100000
#define CCP_SHUTDOWN_ON_COMP2 0x200000
#define CCP_SHUTDOWN_ON_COMP 0x300000
#define CCP_SHUTDOWN_ON_INT0 0x400000
#define CCP_SHUTDOWN_ON_COMP1_INT0 0x500000
#define CCP_SHUTDOWN_ON_COMP2_INT0 0x600000
#define CCP_SHUTDOWN_ON_COMP_INT0 0x700000
#define CCP_SHUTDOWN_AC_L 0x000000
#define CCP_SHUTDOWN_AC_H 0x040000
#define CCP_SHUTDOWN_AC_F 0x080000
#define CCP_SHUTDOWN_BD_L 0x000000
#define CCP_SHUTDOWN_BD_H 0x010000
#define CCP_SHUTDOWN_BD_F 0x020000
#define CCP_SHUTDOWN_RESTART 0x80000000
#define CCP_DELAY 0x1000000 // Multiply this by the delay count
Thank you,
With best regards,
Deepak |
|
![](templates/subSilver/images/spacer.gif) |
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Sat Mar 17, 2007 6:19 am |
|
|
If you read the 16f684 datasheet, specifically Chapter 11, you'll see that these definitions roughly correspond to the modes that can be set up with the control registers. These are all explained in more detail in the text.
r.b. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|