Tjenare!
Har skrivit en tråd förut där jag undrade över hur man får PWM pulser med en PIC16F88 och nu när jag har fått lite bättre koll på detta så ska jag försöka använda A/D omvandling för att styra pulserna med en potentiometer. Är det bara PR2och CCPR1L som måste konfigureras då och hur gör man detta på bästa sätt?
Tack på förhand!
EDIT: Glömde skriva att jag använder en picmicro HP 488 labbplatta och vill gärna använda potentiometern som sitter på den.
Det står en sammanfattning av hur man gör i databladet. CCP1CON används för att konfigurera modulen.
9.3.3 SETUP FOR PWM OPERATION
The following steps should be taken when configuring
the CCP module for PWM operation:
1. Set the PWM period by writing to the PR2
register.
2. Set the PWM duty cycle by writing to the
CCPR1L register and CCP1CON<5:4> bits.
3. Make the CCP1 pin an output by clearing the
TRISB<x> bit.
4. Set the TMR2 prescale value and enable Timer2
by writing to T2CON.
5. Configure the CCP1 module for PWM operation
Finns även en sammanfattning om ADC i kapitel 12
These steps should be followed for doing an A/D
conversion:
1. Configure the A/D module:
• Configure analog/digital I/O (ANSEL)
• Configure voltage reference (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• SET PEIE bit
• Set GIE bit
3. Wait the required acquisition time.
4. Start conversion:
• Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
(with interrupts disabled); OR
• Waiting for the A/D interrupt
6. Read A/D Result register pair
(ADRESH:ADRESL), clear bit ADIF if required.
7. For next conversion, go to step 1 or step 2 as
required. The A/D conversion time per bit is
defined as TAD. A minimum wait of 2 TAD is
required before the next acquisition starts.