Hello, I am having some major problems with the duty cycle of a PWM setup on the 18F452 device. The problems is when I set the following conditions for the PWM: PR2 = 0X7C TMR2[0,1]= 1 ;for 4 bit prescale on timer 2 TOSC = 40MHz system clock With these above settings, that should yield me a 20KHz PWM period, which it does. But the problems is that according to the data sheet, this should allow me a 12-bit resolution, but do to the limits of the PIC this can only be 10-bit. Which also is file. However, the problem occurs when I set the duty cycle. If CCPR1L = 0x80 then I should have a 50% duty cycle, this is without taking into consideration CCPR1CON<5:4> are set, however I am getting a 100% duty cycle. In fact it appears that the value of CCPR1L is 2 times the value of the output duty cycle. I.E if CCPR1L = 128 then the output is 100% if the CCPR1L is anything more that 128, then the output is high perminately. What is the problem. I want to be able to have the full 10-bit range, but how? Below is code that I am using. PulseLaser: GLOBAL PulseLaser ;We begin by moving the high byte in the CCPR1L register. ;Then, we stripp all bits in CMDDATA1(Low 2 bits) but 4 and 5 ;We proceed to clear the previous value in the CCP1CON for the two LSB. ;Finally, we move the two lowest bits in CMDDATA1 into working and then ;IOR that value with the CCP1CON and place the result back into the CCP1CON ;register. ;CMDDATA2 = High 8bits of duty cycle ;CMDDATA1 = low 2 bits of duty cycle ;TRICKEL_PRESCALE=0X04 FOR 16 TMR2 PRESCALE VALUE ;WORK_PRESCALE = 0X01 FOR 4BIT TMR2 PRESCALE VALUE ;TRICKEL_FREQ_PERIOD = 0X7C FOR PR2 yielding a 5KHz PWM frequency ;WORK_FREQ_PERIOD = 0X7C FOR PR2 yielding a 20KHz PWM frequency ;The two above frequencies at determined by the combination of the PR2 and TMR2 prescale settings. MOVFF CMDDATA2,CCPR1L MOVLW B'00110000' ANDWF CMDDATA1,F,A MOVLW B'11001111' ANDWF CCP1CON,F,A MOVF CMDDATA1,W,A IORWF CCP1CON,F,A ;Here we check the value to determine if both values are zero. ;If they are, then pulsing is to be terminated. MOVLW 0X00 CPFSEQ CMDDATA1,A BRA StartPulseTimer CPFSEQ CMDDATA2,A BRA StartPulseTimer ;If we are here, then we are terminating the pulsing of the laser. MOVFF TRICKEL_FREQ_PERIOD,PR2 MOVLW B'00000011' ANDWF TRICKEL_PRESCALE,F,BANKED IORLW B'11111100' ANDWF T2CON,F,A MOVF TRICKEL_PRESCALE,W,BANKED IORWF T2CON,F,A ;Should now be setup. BCF T2CON,TMR2ON,A ;Turn off timer. RETURN StartPulseTimer ;Move frequency into registers. MOVFF WORK_FREQ_PERIOD,PR2 MOVLW B'00000011' ANDWF WORK_PRESCALE,W,BANKED IORLW B'11111100' ANDWF T2CON,F,A BSF T2CON,TMR2ON,A RETURN END Regards, James -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.