Hello,
I've tried to use PWM in 10bits mode for the first time and (almost) everything works fine.
Making some measurements, I notice that the PWM frequency doesn't reach 1kHz as it should (in my opinion). I get around 0,975kHz instead.
Is this due to my 4MHz XTal's or what?
Code:' PIC 16F690 Fuses @ DEVICE FCMEN_OFF @ DEVICE IESO_OFF @ DEVICE BOD_ON @ DEVICE CPD_OFF @ DEVICE PROTECT_OFF @ DEVICE MCLR_OFF @ DEVICE PWRT_OFF @ DEVICE WDT_OFF @ DEVICE HS_OSC ' Registers 76543210 OPTION_REG = %10000101 'PORT A&B Pull-Ups disabled (look WPUA & WPUB) ANSEL = %00010100 'Select analog inputs Channels 0 to 7 ANSELH = %00000010 'Select analog inputs Channels 8 to 11 ADCON0 = %00000001 'A/D Module is ON (Bit5:2 select channels 0:11) ADCON1 = %00000000 'A/D control register CM1CON0 = %00000000 'Comparator1 Module is OFF CM2CON0 = %00000000 'Comparator2 Module is OFF INTCON = %10100000 'INTerrupts CONtrol (TMR0 ON) TRISA = %00000000 'Set Input/Output (0 to 5) PORTA = %00000000 'Ports High/Low (0 to 5) TRISB = %00000000 'Set Input/Output (4 to 7) PORTB = %00000000 'Ports High/Low (4 to 7) TRISC = %00000000 'Set Input/Output (0 to 7) PORTC = %00000000 'Ports High/Low (0 to 7) ' HPWM registers T2CON = %00000101 'Timer2 = ON (bit2), prescaler = 4 CCP1CON = %00001100 'Select PWM Mode CCPR1L = 0 CCP1CON.5 = 0 CCP1CON.4 = 0 PR2 = 255 DutyCl var word dutycl = 856 TEST: CCPR1L = dutycl >> 2 CCP1CON.5 = Dutycl.1 CCP1CON.4 = Dutycl.0 pause 1000 goto test





Bookmarks