Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PWM to generate a square clock signal on output pin

Status
Not open for further replies.

PoS080

Junior Member level 3
Joined
Apr 2, 2017
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
243
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.
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:

Maybe you have the 'scope on AC coupling? The PIC
is not likely supplied with -2.5V and +2.5V.
 

Hmm, I think you are right.

I am powering my pic with a five volt supply. The Oscope I am using has the following pins

AGND, 0+, 0-, 1+, 1-. Where 0 and 1 represent the two channels. Currently, I have my pic output in connected to 0+, and a ground connection to AGND. Do i need to connect something to 0-?

I will go to school tomorrow and use the big oScope to check.
 

I would attach O- to your ground reference point.
The naming indicates they are differential inputs,
leaving one open may in effect be AC-coupling (DC
blocking, by the open O- connection) the waveform.

Try, and see.
 
  • Like
Reactions: PoS080

    PoS080

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top