yes i tried simulate the program using real pic simulator.
so my codes is below:
DEFINE OSC 20
DUTY1 VAR WORD
DUTY2 VAR WORD ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
TRISC.2 = 0 ' Set PORTC.2 (CCP1) to output
CCP1CON = %00001100 ' Set CCP1 to PWM
T2CON = %00000101 ' Turn on Timer2, Prescale=4
PR2 = 249 ' Set PR2 to get 1KHz out
Main:
'Set up a loop for 45 iterations, Duty1 will count 0,1,2,3,4....44
For DUTY1 = 0 TO 44
'Go into the table and retrieve the value pointed at by Duty1 and put that value in Duty2
LookUp DUTY1, [0,18,35,53,70,87,104,120,135,150,164,177,190,201,2 11,221,229,236,_
243,247,251,254,255,254,251,247,243,236,229,221,21 1,201,189,_
177,164,150,135,120,104,87,70,53,35,18,0],DUTY2
'Duty2 now contains the value from the lookup table that Duty1 points at. First time thru the loop it's 0 second time it's 18 and so on.
CCP1CON.4 = DUTY2.0 ' Setup 10-bit duty cycle as
CCP1CON.5 = DUTY2.1 ' a 10-bit word
CCPR1L = DUTY2 >> 2
Pause 10 'Use each dutycycle value 10ms before going to the next one.
Next DUTY1
GoTo Main 'And do it all over again
End
but turns out the duty cycle doesnt come out fully as in the lookup table.
the PWM generated is not completed.
maybe i miss something important?
please help check
photoelectric
Bookmarks