pwm help needed

Status
Not open for further replies.

Hetal

New Member
hi i need help for my design project which involves. workign on the buck converter and the feedback control is done usinn pwm by pic 16f87. i was wondering if any1 could help me in using assembly language. i tried programming on my own.but it seems difficcult.

another question tht arisis is .. do i need A/Dconverter which is not inmy pic.

my proj involves stepping down the voltage from 10 volts to 6 volts and we need a regulated output wiht the help of the pic 16f87.

need urgetn help as i am not a programming person.

thank u
 
searched

i have gone thru the application notes.. and they show me how to programthe pwm mode. however i have one ques. my pic doesnt have the a/d conversion . do i really need it and can ane1 help me wiht a source file which i can strt wiht in programming as i am new it it
 
The 87 doesn't have ADC but it does have comparators. You can use the comparator with a voltage divider to monitor your output voltage.

Mike.
 
this is the code that i have formulated for my pic with a 60percent duty cycle, i woouldjust like to kno if it is correct. plus i need help in programming how to change the duty cycle, how to read form the ports and change the dutycycle value eventually

PWM control

;Setup for PWM operation

; Setting the constants
STATUS equ 03h
PORTB equ 06h
T2CON equ 12h
CCPR1L equ 15h
CCP1CON equ 17h
PR2 equ 92h
TRISB equ 86h

; 1) Set the PWM period by writing to the PR2 register
bsf STATUS,5
movlw 3Fh
movwf PR2
bcf STATUS,5

;2) Set the PWM duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits
movlw 26h
movwf CCPR1L

bsf CCP1CON,4; CCP1Y
bcf CCP1CON,5; CCP1X

;3) Make the CCP1 pin an output by clearing the TRISB<1> bit.
bsf STATUS,5
bcf TRISB,0
bcf STATUS,5

;4)set the TMR2 prescale value ad enable Timer2 by writing to T2CON

movlw 4h
movwf T2CON

;configuring the CCP1 module for PWM operation

movlw fh ; 00001111
movwf CCP1CON
 
Some notes that will help us to help you;

(1) Use the processor include file instead of equating register names.
(2) Use the actual bit names from the include file instead of bit numbers.

People enjoy studying well written, formatted, and commented code.

Good luck. Kind regards, Mike

BTW, it does appear that you are setting up PR2 and CCPR1 correctly for a 60% duty cycle.

Code:
        list p=16F88, b=8, c= 102, n=71, t=on, st=off, f=inhx32
;******************************************************************
;*                                                                *
;*  Filename: 16F88 PWM.asm                                       *
;*    Author: Mike McLaren, K8LH  (k8lh_at_arrl.net)              *
;*      Date: 20-Jun-05  (last revision 20-Jun-05)                *
;*                                                                *
;*   PWM Test Program                                             *
;*                                                                *
;*   Using a 16F88 with 20-MHz clock                              *
;*                                                                *
;*                                                                *
;*     MPLab: 7.11    (tabs=8)                                    *
;*     MPAsm: 4.01                                                *
;*                                                                *
;******************************************************************

        #include        <p16f88.inc>
        errorlevel      -302

        __CONFIG   _CONFIG1, _CCP1_RB0&_LVP_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC
        __CONFIG   _CONFIG2, _IESO_OFF & _FCMEN_OFF

;******************************************************************
;*                                                                *
;******************************************************************

        org     0x0000

RESET   clrf    STATUS          ;                                 |B0
        clrf    PORTA           ; clear Port A data latches       |B0
        clrf    PORTB           ; clear Port B data latches       |B0
        movlw   h'07'           ;                                 |B0
        movwf   CMCON           ; turn comparator off             |B0
        bsf     STATUS,RP0      ; select bank 1                   |B1
        clrf    ANSEL           ; digital I/O, no ADC pins        |B1
        clrf    TRISA           ; port A all outputs              |B1
        clrf    TRISB           ; port B all outputs              |B1
        bcf     STATUS,RP0      ; select bank 0                   |B0
;
;  setup PWM (20-MHz clock)
;
        movlw   b'00000010'     ;                                 |B0
        movwf   T2CON           ; TMR2 prescale:16 (3.2-usecs)    |B0
        movlw   d'010'          ;                                 |B0
        movwf   CCPR1L          ; 10% duty cycle?                 |B0
        bsf     STATUS,RP0      ; select bank 1                   |B1
        movlw   d'100'-1        ; 100 3.2-usec 'ticks'            |B1
        movwf   PR2             ; Period=320-usecs, Freq=3125-Hz  |B1
        bcf     STATUS,RP0      ; select bank 0                   |B0
        movlw   b'00001100'     ;                                 |B0
        movwf   CCP1CON         ; put CCP module in PWM mode      |B0
        bsf     T2CON,TMR2ON    ; turn on TMR2                    |B0
;
;  now test to see if the LED on RB3 is glowing at 10% brightness
;
LOOP    goto    LOOP            ;loop indefinately                |B0
;
;******************************************************************
    end
 
Last edited:
few questions regarding the code


thnk u for the codee..
 
For the case when using a value for PR2 of d'100'-1, a CCPR1L value of 10 will provide a duty cycle of 10% and a CCPR1L value of 60 will provide a duty cycle of 60%.

For the case when using a value for PR2 of d'200'-1, a CCPR1L value of 20 will provide a duty cycle of 10% and a CCPR1L value of 120 will provide a duty cycle of 60%.

A point of confusion with PIC PWM is that PR2 uses 'ticks' of Tcyc (reciprocal oscillator freq/4) while CCPR1L:CCP1X:CCP1Y use 'ticks' of Tosc (reciprocal oscillator freq). If you ignore the CCP1X:CCP1Y bits you've effectively multiplied Tosc by 4 and CCPR1L represents 'ticks' in the same time base that PR2 is using. For example; if PR2 = d'256'-1 then a 50% duty cycle is achieved when CCPR1L is set to d'128' (ignoring CCP1X:CCP1Y).

As for modifying CCPR1L:CCP1X:CCP1Y "on the fly" to change PWM duty cycle, you'll have to figure that out on your own. I can't imagine how you'll do it for this application without an ADC module but I suspect there are several creative minds on the forum who can help.

It seems you may be a beginner, and if so, I'd recommend you search for the Elmer 160 tutorial series and study.

Good luck with your project. Kind regards, Mike
 
another query





thnks a lot for the information. i will go thru the tutorial.

i just have one more ques , i am confused. i need my output to be 6 volts so that means i have to connect my vref pin to 6 volts?? and how do i program this part ?


or is it tht the microcontroller needs 5v to power up soo the output will also b 5v?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…