Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F88 PWM and A/D conversion

Status
Not open for further replies.
They even stack the zeners, when charging the supercaps ..
so far i got a very small program , programmed and running on the 628..yay !! ya gotta remember its been months since i programmed a pic..
next step is to program the 16F88..i understand that the A/D converter is selected and available from the get go..?
this should be fun.. 8)
 
i cant find it .. but what i saw showed several layers of caps in parallel with zener diodes , to make sure that each caps voltage did not excede the 5.5 V maximum..
 
I got them ..
and tried two in parallel , with a NiMH cell below them ..
so i charged caps up to 5V then connected the cell , then connected that to a 100 ohms resistor , then connected diode ..
diode current started @ 13 mA and 4.5 mins. later current was 1.3 mA..
so it should last twenty mins. without blinking at all . but i still want to use PWM and the A/D converter of the PIC 16F88..
 
sadly i'm not getting anywhere with my PWM routine
i need help.. getting started..
i have been looking at the PDF for days !! :cry:
if i have a templet to go by , i can make changes as needed..
What i need is a 10 precent duty cycle PWM signal running at 100 HZ with a 5.068 Mhz clock on a 16F628..
thanks in advance :)
 
Code:
The next step is to set T2CON, this sets the frequency of the PWM, as it's derived from the 20MHz system clock it runs too at too high a frequency, there are two possibilities here - setting the prescaler divides the frequency before the PWM section, and the postscaler afterwards. For this example we set the prescaler to divide by 16, this gives us a PWM frequency of 2500Hz.
is he saying that 20MHZ /16 = 2500HZ ?
 
williB said:
Code:
The next step is to set T2CON, this sets the frequency of the PWM, as it's derived from the 20MHz system clock it runs too at too high a frequency, there are two possibilities here - setting the prescaler divides the frequency before the PWM section, and the postscaler afterwards. For this example we set the prescaler to divide by 16, this gives us a PWM frequency of 2500Hz.
is he saying that 20MHZ /16 = 2500HZ ?

The calculation should be as follows:

PWM Period = [(PR2) + 1] • 4 • Tosc • Prescale (see section 8.3.1 of the PIC16F87XA datasheet)
PWM Period = [124+1] * 4 * 0.05usec * 16
PWM Period = 400usec. for a 2500Hz frequency.

The correct PR2 value should be 124 not 126 to get 2500Hz.
 
williB said:
so if my clock is 39600hz
prescale is 1
pwm period is .001sec (1000 HZ)
then
PR2 = 9.. right?

Yes. PR2 is about equal to 9. However, if you set the PR2 to a very low value, the number of PWM duty cycle slices steps will be very low. In this case, it's just 36 slices (9*4).
 
Great !!
so my clock is 5,068,800 HZ divide that by 8..gives 633,600 Hz clock into PIC..
with a 1000 HZ PWM Freq.
and a prescale of 1..
gives
.001 = ((PR2+1) * 4) / 633600
PR2= 157
and my number of different steps is 633 .
that really helped , because i saw that equation but without your explaination it didnt sink in.. :oops:
 
williB said:
Great !!
so my clock is 5,068,800 HZ divide that by 8..gives 633,600 Hz clock into PIC..
with a 1000 HZ PWM Freq.
and a prescale of 1..
gives
.001 = ((PR2+1) * 4) / 633600
PR2= 157
and my number of different steps is 633 .
that really helped , because i saw that equation but without your explaination it didnt sink in.. :oops:

I suggest you try reading my tutorial, which makes thinks a little clearer - PR2 basically sets the number of steps, but the tutorial gives the simple sequence of steps that I used.
 
i think i finally have it.. Yay !
*goes off to test it out*
 

Attachments

  • pwm____timer2.jpg
    pwm____timer2.jpg
    56.3 KB · Views: 725
  • pwm_setup.jpg
    pwm_setup.jpg
    34.1 KB · Views: 740
Nigel Goodwin said:
williB said:
Great !!
so my clock is 5,068,800 HZ divide that by 8..gives 633,600 Hz clock into PIC..
with a 1000 HZ PWM Freq.
and a prescale of 1..
gives
.001 = ((PR2+1) * 4) / 633600
PR2= 157
and my number of different steps is 633 .
that really helped , because i saw that equation but without your explaination it didnt sink in.. :oops:

I suggest you try reading my tutorial, which makes thinks a little clearer - PR2 basically sets the number of steps, but the tutorial gives the simple sequence of steps that I used.

Tutorial8 needs correcting. The PWM frequency calculations don't add up. That caused WillieB to ask for help.
 
https://www.electro-tech-online.com/custompdfs/2005/06/33023a.pdf
page 216
i think this is wrong also
Code:
CLRF CCP1CON ; CCP Module is off
CLRF TMR2 ; Clear Timer2
MOVLW 0x7F ;
MOVWF PR2 ;
MOVLW 0x1F ;
MOVWF CCPR1L ; Duty Cycle is 25% of PWM Period
CLRF INTCON ; Disable interrupts and clear T0IF
BSF STATUS, RP0 ; Bank1
BCF TRISC, PWM1 ; Make pin output
CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0 ; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 0x2C ; PWM mode, 2 LSbs of Duty cycle = 10
MOVWF CCP1CON ;
BSF T2CON, TMR2ON ; Timer2 starts to increment
;
; The CCP1 interrupt is disabled,
; do polling on the TMR2 Interrupt flag bit
;
PWM_Period_Match
BTFSS PIR1, TMR2IF
GOTO PWM_Period_Match
;
; Update this PWM period and the following PWM Duty cycle
;
BCF PIR1, TMR2IF

fifth line down MOVLW 0x1F ;
is indeed 25% of the PWM Period

thirteenth line down MOVLW 0x2C ; PWM mode, 2 LSbs of Duty cycle = 10
but when you tack on the two LSBs of the duty cycle
it dosnt make any sence..
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top