PWM setup for PIC16F873A

Status
Not open for further replies.

junhao_wu

New Member
Hi Guys! I have just programed my PWM code into PIC16F873A...was wondering if I just connect +5V to VDD, Ground my Vss, I should expect a square wave(PWM) at CCP1 pin?? or do i have to connect some circuity?

below is my C code.

#pragma chip PIC16F873A
#include "math24f.h"
void int_pwm(void)
{
int duty;
CCP1CON = 0;
TMR2 = 0;
TRISC.2 = 0;
PORTC.2 = 0;
PIE1.1 = 0;
PIE1.2 = 0;
PR2 = bin(00111110);
CCP1CON.5 = 0;
CCP1CON.4 = 0;
duty = bin(00011111);
CCPR1L = bin(00011111);
T2CON = bin(00000000);
CCP1CON = bin(00001100);
}
void main(void)
{
int_pwm();
T2CON.2 = 1;
while(1);
}

Pls kindly advise.... thank for inputs
 
I haven't looked carefully at your code yet, but can't you just simulate it? or does whatever compiler package you're using not allow that? From your code it looks to me like you might be using CC5x, which I've heard will allow simulation from within MPLAB... I would also recommend BoostC to you, which has an IDE and also integrates with MPLAB, either one of which allows you to run simulations before you worry about trying it out on a real PIC.

The PWM module doesn't require any external circuitry to operate, so as long as your code is correct you should see an output...
 
and make sure your setting are good for the osc speed you're using. Same for your config fuses.

i don't know if this software may help you, but anyways...
**broken link removed**
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…