Je cherche à faire fonctionner un signal PWM sur le PIN de RB5 d'un PIC16F1779. J'ai l'impression que le datasheet demande de faire plusieurs choses différents. Par exemple à la page 317 dans les étapes à suivre on ne parle pas de PR2 alors qu'à la page d'après il y en a besoin pour définir la période??
Il faut deviner des registres... J'ai déjà plusieurs fois programmé un signal PWM sur des PICs mais sur celui là j'ai vraiment du mal.
Voilà ce que j'ai pour l'instant. J'utilise le Timer6 (juste pour mieux me repérer avec les indices) et le programme reste bloqué dans le while. Probablement c'est pas PWM6IF le bon timer interrupt bit du point 7)
Code : Tout sélectionner
CCP1PPS = 0b00001101 ; // RB5
// 1) :
TRISBbits.TRISB5 = 1 ; // "éteindre" pin RB5
// 2) :
CCPTMRS1bits.C1TSEL = 0b10 ; // Timer6 pour CCP1
// 3) :
PR2 = 0b11111111 ; // 255
// 4) :
CCP1CON = 0b10001100 ; // Enable + PWM mode
// 5) :
CCPR1H = 0b00000010 ;
CCPR1L = 0b00000000 ;
// 6) :
PIR6bits.PWM6IF = 0 ; // Timer interrupt flag
T6CONbits.CKPS = 0b000 ; // Prescal = 1:1
T6CONbits.ON = 1 ;
// 7) :
while(PIR6bits.PWM6IF==0) ;
TRISBbits.TRISB5 = 0 ; // "allumer" pin RB5Voilà les étape du datasheet Page 317 que je suis :
Code : Tout sélectionner
1. Disable the CCPx pin output driver by setting the
associated TRIS bit.
2. Select the timer associated with the PWM by
setting the CCPTMRS register.
3. Load the associated T2PR/T4PR/T6PR/T8PR
register with the PWM period value.
4. Configure the CCP module for the PWM mode
by loading the CCPxCON register with the
appropriate values.
5. Load the CCPRxH:CCPRxL register pair with
the PWM duty cycle value.
6. Configure and start the timer selected in step 2:
• Clear the timer interrupt flag bit of the PIRx
register. See Note below.
• Configure the CKPS bits of the TxCON
register with the Timer prescale value.
• Enable the Timer by setting the ON bit of
the TxCON register.
7. Enable PWM output pin:
• Wait until the Timer overflows and the timer
interrupt bit of the PIRx register is set. See
Note below.
• Enable the CCPx pin output driver by
clearing the associated TRIS bit.

