Hello, it's me again.
I went through the registers in the datasheet and used the example of Bruce here : http://www.picbasic.co.uk/forum/showthread.php?t=6768
I tried to understand and apply it to my case, but it's not doing anything my duty cycle ?
Thank you in advance for your help, it'd be really appreciated
Code:
Duty VAR Word
TRISA = %11111111
TRISB = %00000000
TRISC = %00000010
TRISD = %00000000
TRISE = %00000000
' Analog setup
' Single shot, single channel, Group A is taken and converted, A/D converter enabled
ADCON0 = %00000001
'
ADCON1 = %00010000
ADCON2 = %11001111 ' Right justified, 24 Tad, Frc
ADCON3 = 0 ' Disable all triggers
ADCHS = 0 ' Channel select for AN0
ANSEL0 = %00000001 ' AN0 analog input, rest digital
PORTB = 0
PORTD = 0 ' clear port
PTCON0=$00 'timebase
PTPERL=$A0 ' $01A0 = 12kHz
PTPERH=$01
PWMCON0 = %01001111
PWMCON1=%00000001
DTCON=$00
OVDCOND = %00000000
OVDCONS = %00000000 'PORT PINS
PDC0L=$00
PDC0H=$00
PDC1L=$00
PDC1H=$00
PDC2L=$00
PDC2H=$00
PDC0L = Duty.LowByte
PDC0H = Duty.HighByte
PDC1L = Duty.LowByte
PDC1H = Duty.HighByte
PDC2L = Duty.LowByte
PDC2H = Duty.HighByte
PTCON1=%10000000
GoTo Main
Main:
ADCON0.1 = 1 ' Start the conversion
While ADCON0.1=1 ' Wait for it to complete
Wend
Duty.HighByte = ADRESH ' get result from AN0
Duty.LowByte = ADRESL ' Increment buffer pointer
OVDCOND = %00000010 'PWM on PWM1
Bookmarks