PIC16F628

From Eric

Revision as of 21:00, 2 February 2011 by Ejenn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Présentation générale

(A compléter)

On trouvera un outil d'aide à la sélection d'un microcontrôleurs PIC ici.

Commande PWM

Exemple de configuration du PWM pour une fréquence de 10KHz.

; -----------------------------------
; Setup PWM 
; -----------------------------------
bsf 	STATUS,	RP0		; Select bank 1

; Set the PWM period by writing to the PR2 register.
movlw d'99'
movwf PR2

bcf 	STATUS,	RP0		; Select bank 0
; Set the PWM duty cycle by writing to 
;  CCPR1L (MSB) CCP1CON<5:4> (LSB).
; The resolution is log(fosc / (FPWM x TMR2 prescaler)) / log(2) # 8.62 bits
; Initially: 0% (
clrf CCPR1L
	
; Make the CCP1 pin an output by clearing the TRISB<3> bit.
; (done later)

; Set the TMR2 prescale value 
movlw d'1'
movwf TMR2

; Enable Timer2
bsf T2CON,TMR2ON

; Configure the CCP1 module for PWM operation.
; Bits CCP1CON<5:4> : LSBs of duty cycle set to 0
movlw b'001100'
iorwf CCP1CON,f

; Nota : TPWM = (PR2+1)*4*TOSC*TMR2 
;             = (99+1)*4*1/4e6*1 = 1e-4 => 10KHz

Les formules de calcul de la fréquence du signal PWM et de son rapport cyclique sont donnés dans la documentation.

Personal tools