PIC 12f683 AD/PWM Problems:
Hi!
Iīve got a Problem again. This time I read an 10 bit AD Value an want to put it Out as PWM on Port GP2
Something is wrong with the AD module.
Here is my Code:
'READ 10 BIT AD Value and put out as PWM
@ device pic12f683, fcmen_off, ieso_off, intrc_osc, wdt_off
@ device pic12f683, pwrt_on, mclr_off, protect_off
GPIO = %00000000 ' All outputs low
CMCON0 = 7 ' Comparators off
TRISIO = %00000001 ' Set GP0 in and Rest Out 0=Output
ANSEL = %00000001 'Set PORTGPIO.0 analog rest digital
'WPU=%00110000 ' Pull-ups on for GPIO.4 & 5 inputs
'OPTION_REG.7=0 ' Enable internal pull-ups
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
Define CCP1_REG GPIO 'PWM Output on gpio
Define CCP1_BIT 2 'Bit 2
adval Var Word ' Create adval to store result
Pause 100
loop:
ADCIN 0, adval ' Read channel AN0 to adval
HPWM 1,adval,500 ' PWM between 0-1024 , 500Hz on GP2
Pause 100
Goto loop ' Do it forever
End
---------------------------------------------------------------------
If I donīt Use the ADCIN, and would say adval = 100 or something else between 0 an 255, I can see the right PWM with the scope coneccted to GP2
but if adval gets the Value from ADCIN, the PWM Output sometimes is on or off, It looks like that there some definition is missing. I couldnīt imagine which one this could be.
Answer in the Question...
hi, Surfer
The ADC result is between ???
The PWM valid input range is between ???
SCALING forgotten ...
Alain