PoS080
Junior Member level 3
Hello EE friends,
I am trying to use PWM to generate a square wave signal on one of the output pins of my pic16F1829 chip.
My issue is that I am getting a square wave that goes between -2.5 to 2.5 to give 5vpp. I am wanting a wave that goes 0 to 5 v. Please bear with me as am still a student and still learning.
Chip: PIC 16F1829
Complier: XC8
IDE: MPLAB
I used an online PWM calculator to generate the following register values.
This is my code as of right now, as well as a oscope img.
I am trying to use PWM to generate a square wave signal on one of the output pins of my pic16F1829 chip.
My issue is that I am getting a square wave that goes between -2.5 to 2.5 to give 5vpp. I am wanting a wave that goes 0 to 5 v. Please bear with me as am still a student and still learning.
Chip: PIC 16F1829
Complier: XC8
IDE: MPLAB
I used an online PWM calculator to generate the following register values.
Code:
/*
* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 5000.00 Hz (Requested : 5000 Hz)
* Duty Cycle = 50 %
* Resolution is 9 bits
* Prescaler is 4
* Ensure that your PWM pin is configured as digital output
* see more details on http://www.micro-examples.com/
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b00110001 ;
T2CON = 0b00000101 ;
CCPR1L = 0b00011000 ;
CCP1CON = 0b00111100 ;
This is my code as of right now, as well as a oscope img.
Code:
#include <xc.h>
#define _XTAL_FREQ 4000000.0 /*for 4mhz*/
int main(int argc, char** argv){
APFCON1 = 0X00; //This reassigns CCP module #2 to use RC3 PIN OUT
OSCCON = 0X6A; //Sets CPU clock Fosc=4MHz
TRISC = 0; //Sets C for output
PORTC = 0; // Clears PortA
PR2 = 0b00110001 ;
T2CON = 0b00000101 ;
CCPR2L = 0b00011000 ;
CCP2CON = 0b00111100;
return (EXIT_SUCCESS);
}
Last edited by a moderator: