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.

PWM control output problem

Status
Not open for further replies.

papaonn

Newbie level 5
Joined
Jul 26, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
Hi there i have some problem with PWM control,
I am using PIC16F877A microchip.

I have read some articles online and found that there is a PSTRCON register to control the output of PWM, which are P1A, P1B, P1C, & P1D.
however, i compiled my code in MPLAB (HI-TECH C compiler), it gave me an error saying that 'PSTRCON undeclared identifier'.

I have searched thru the internet and found no result about why it gave me undeclared identifier,
I included both <pic.h> & <htc.h> and got no results still.

I am wondering if there is necessary to switch on PSTRCON register,
or there is another way to generates output from PWM,

ALL I want to do is just 'Get some output from PWM signals to drive motors',
can somebody show me the way?

Thanks so much!

Regards,
Daniel.
 


the PIC16F877A does not have a PSTRCON register see
https://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

perhaps you were looking at code for a PIC16F690 which does have a PSTRCON register

do a web search for "PIC16F877A PWM tutorial", you should get plenty of links, e.g.
https://roboticsforyou.blogspot.co.uk/2008/12/ccp-pic16f877a-mikroc-code-tutorials.html

Hi there thank you so much for telling me this,
however the tutorial you given are of microC programming library, i am using Hitech C and hence would not be applicable, still thank you so much =)
 

below is some sample PWM code for a PIC16F917 running on a Microchip PICDEM mechatronics board
**broken link removed**

I think the PIC16F917 uses the same registers as a PIC16F877A
Code:
// initialise PWM using Capture Compare PWM Module 2
void PWMinitialise(void)
{
        // assume Fosc uses oscillator 8MHz - call systemInitialise() first
        TRISD2=0;                // set RD2/CCP2 is output
        TRISD7=0;                // set RD7 is output
        PR2=0x3f;                // set PR2 to 31.2 kHz PWM (PWM value will be 8 bits)
        // Configure Capture Compare PWM Module 2
        CCPR2L=0;                // set PWM duty cycle to 0
        CCP2CON=0xC;             // set PWM mode
        TMR2ON=1;                // Turn on Timer 2 PWM
}

// set PWM duty cycle - value between 0 and 100
void PWMcontrol(int dutyCycle)
{
        // get 8 bit value for PWM control at 31.2 kHz PWM
        dutyCycle = (int) (dutyCycle * 255L / 100L);             // get 8 bit value
        RD7=1;                                                   // switch on motor
        // load most significant 6 bits in CCPR2l and least significant two bits in CCP2CON
        CCPR2L=dutyCycle >> 2;                          
        CCP2CON = (CCP2CON & 0xF) + ((dutyCycle << 4) & 0x30);   // set bits 4 and 5
}
 

sincerely thanks so much for the reply and help,

i've got a new problem right here,
if i am to drive a 12V/5A motor with Hbridge circuit,
how am i going to send my pwm signal from my PIC16F877A which doesn't even provide up to 5V current?
thanks so much.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top