News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

10 Bit Resolution PIC16F684

Started by Abdullah, Today at 09:11 AM

Previous topic - Next topic

Abdullah

HI everyone
I have a question.
Can the PWM resolution of the PIC16F684 be used at a higher bit resolution when using a 20MHz crystal?
Normally the duty cycle operates in 8-bit resolution (0 to 255).
I it possible to convert or extend this to a range of 0 to 1024 (i.e.,10-bit resolution)?
Abdullah

Pepe

#1
demo proteus 10 bits pwm


Device = 16F684
Config FOSC_HS, WDTE_OFF, PWRTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF
Declare Xtal = 20
Declare Create_Coff On
Declare Optimiser_Level 3
Declare Watchdog Off
Declare Adin_Res 10
Declare Adin_Tad FRC
Declare Adin_Stime 50
TRISA = %00000001        ' RA0 = ADC input
TRISC = %11011111        ' RC5 = PWM output
ANSEL  = %00000001       ' AN0 enabled only
ADCON0.7 = 1            '
PR2 = 255                 '
T2CON = %00000100        ' Timer2 ON, prescaler 1
CCP1CON = %00001100      ' CCP1 PWM mode

Dim adc_val As Word
Dim duty    As Word
Dim dutya    As Word

Do
    duty = ADIn 0
   
    If dutya<>duty Then
                       dutya=duty
                       CCP1CON.4 = duty.0 
                       CCP1CON.5 = duty.1
                       CCPR1L = duty >> 2
                       DelayUS 100
     EndIf
Loop