MoRoH
New Member
OK,
I want my PIC16F873A to take in 0 to 5vdc, it will output a 10bit adc number where 0v = 0000000000 and 5V = 1111111111. It will also output a PWM wavefrom where 0v = 0% dutycycle 2.5v = 50%duty and 5v = 100%duty.
ADC and PWM both work on simulator
PWM output on CCP2
10 bits numers on RB0-RB7 and 2 MSB on RC6 and RC7
when i hooked it up it does not work, here is my a basic schematic of what is hooked up

I want my PIC16F873A to take in 0 to 5vdc, it will output a 10bit adc number where 0v = 0000000000 and 5V = 1111111111. It will also output a PWM wavefrom where 0v = 0% dutycycle 2.5v = 50%duty and 5v = 100%duty.
ADC and PWM both work on simulator
PWM output on CCP2
10 bits numers on RB0-RB7 and 2 MSB on RC6 and RC7
when i hooked it up it does not work, here is my a basic schematic of what is hooked up
Code:
unsigned int duty_cycle; //
unsigned int adc_val;
void InitMain() {
ADCON1 = 0xfe; // All ADC pin 1 to on
TRISA = 0x01; // PORTA is input
TRISB = 0x00 ; //Set Port RB0-RB7 to LSB
TRISC = 0x3F; // Pins RC7, RC6 are outputs MSB
PORTC = 0; // intitialize port C to 0
Pwm_Init(5000); // Initialize PWM module
// Timer 2
PR2=62;
T2CON = (1<<TMR2ON);
// Initialize Control PWM
CCPR1L = 50; // Initial Duty
CCP1CON = 0x0f; // PWM mode set and 5,4 duty = 0
}
void main() {
InitMain();
Pwm_Start(); // Start PWM
while (2) //Start while loop
{
adc_val = adc_read(0) ;
portb = adc_val ;
portc = adc_val >> 2; // Send 2 most significant bits to Rc7, Rc6
adc_val = adc_read(0); //read analog input RA0
duty_cycle=adc_val*64; // CALIBRATED IT BY CHANGIN 100 TO 64
duty_cycle/=1024;
CCPR1L = duty_cycle;
}
}