Dear All, I have loaded following program to the 16F877. I'm expecting a 5kHz PWM = output duty according to the A/D input. But it only gives out 5kHz PWM = output embedded in a 53Hz (approx.) 50% duty square signal. My xtal runs = at 20MHz. I have tried shielding clock wire but to no good. Why is this? Regards Dilan Amarasinghe ORG 0 ; Initializing PWM Module BANKSEL PR2 ; Bank 1 MOVLW 0xFF MOVWF PR2 ; PR2 =3D 256=20 BCF TRISC, 2 ; CCP1 -> output BANKSEL CCPR1L ; Bank 0 MOVLW B'01111111' ; Duty =3D 127 (50%) MOVWF CCPR1L BSF CCP1CON, 5 ; 2 LSBs of CCP1 BSF CCP1CON, 4 BSF T2CON, 0 ; Prescale =3D 4 BCF T2CON, 1 BSF T2CON, 2 ; TMR2 ON BSF CCP1CON, 3 BSF CCP1CON, 2 ; CCP1 -> PWM Mode ; Initializing ADC Module =20 BANKSEL ADCON1 ; Bank 1 BCF ADCON1, PCFG3 ; AN0 =3D input channel BCF ADCON1, PCFG2 ;=20 BCF ADCON1, PCFG1 ;=20 BCF ADCON1, PCFG0 ; BCF ADCON1, ADFM ; Left justify the results BANKSEL ADCON0 ; Bank 0 BCF ADCON0, CHS0 ; Cha. 0 =3D Analog i/p BCF ADCON0, CHS1 ; BCF ADCON0, CHS2 ; BSF ADCON0, ADCS1 ; Conv. clk =3D 32Tosc BCF ADCON0, ADCS0 ; BCF INTCON, GIE ; Disable all ints BANKSEL PIE1 ; Bank 1 BCF PIE1, ADIE ; Disable ADC int BANKSEL ADCON0 BSF ADCON0, ADON ; Sets ADC -> ON BANKSEL TRISB ; Bank 3 CLRF TRISB ; Set PORTB as output ; ADC Control and Looping BANKSEL ADCON0 ; Bank 0 loop BSF ADCON0, GO poll NOP BTFSC ADCON0, GO GOTO poll MOVF ADRESH, W ; Move result to W =20 MOVF ADRESH, 1 MOVWF CCPR1L ; Adjust the PWM duty with Analog input BANKSEL PORTB ; Bank 2 MOVWF PORTB GOTO loop END -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads