Graham North wrote: > > Thanks for the program. > > Am I right by looking at the program that the input from the 10k pot should > be connected to RA0? > > Which port is the output? > > BCF TRISC,2 ;MAKE PIN OUTPUT > > Is it port C? All 8 leds connected. > > Sorry for the dumb questions. > > Thanks Graham Graham, there are no such thing as dumb questions, only dumb answers. I am not referring to the other replies to your email of course :). I did not see the program that Tony wrote, but it should be very similar to this A/D to PWM test program below (I modified the tutorial A/D program for the ICD, bit rough, but it works). To answer your questions: The 10K pot is connected to RA0 and the pin is set up to be an analogue input. BCF TRISC,2 is the CCP1 output on PortC which is set up to be the PWM1 output. Get the Mid-Range MCU Family Reference Manual from Microchip. It will give you a bit more info (You can also get it from Microchip's web with each chapter as a separate download, get the CCP section). To do PWM: Set up TMR2, switch TMR on and set prescaler (16 in this case). Set TMR2 period in PR2. Default is 0x0FF. You should only change this setting lower if you want a faster PWM period (together with the prescaler), but then you start meddling with resolution. Clear TMR2 interupts in PIR2 and PIE2 (You don't need them for simple PWM) Should be cleared as default. Do the calculations (in the data books) to see if your duty cycle is not longer than the period. The above settings should keep you in spec. Set CCP1CON to be PWM. Write your PWM duty cycle to CCPR1L (8 MSB) and CCP1CON, 5 and 4 (2 LSB) and away you go! Hope this helps Quentin ;A/D input on RA0 to PWM output on RC2 Start banksel PORTC clrf PORTC ;Clear PORTC movlw B'01000001' ;Fosc/8, A/D enabled movwf ADCON0 banksel OPTION_REG movlw B'10000111' ;TMR0 prescaler, 1:256 movwf OPTION_REG clrf TRISC ;PORTC all outputs movlw B'00001110' ;Left justify,1 analog channel movwf ADCON1 ;VDD and VSS references banksel PORTC MOVLW B'00000111' ;switch on TMR2 and set prescaler to 16 MOVWF T2CON MOVLW B'00001100' MOVWF CCP1CON ;select CCP1 to be PWM output Main btfss INTCON,T0IF ;Wait for Timer0 to timeout goto Main bcf INTCON,T0IF bsf ADCON0,GO ;Start A/D conversion Wait btfss PIR1,ADIF ;Wait for conversion to complete goto Wait DO_PWM movf ADRESH,W ;Write A/D result to PWM MOVWF CCPR1L BCF CCP1CON,4 ;do the LSB BCF CCP1CON,5 BSF STATUS,RP0 MOVF ADRESL,W BCF STATUS,RP0 MOVWF TEMP1 BTFSC TEMP1,6 BSF CCP1CON,4 BTFSC TEMP1,7 BSF CCP1CON,5 goto Main ;Do it again