ANSEL configures A/D pins as digital or analog. CMCON0=7 disables analog
comparators, and TRISIO is the TRIS reg on this one, so,
Code:
@ device pic12F683, hs_osc, wdt_off, mclr_off, protect_off
DEFINE OSC 20
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3 ' Frc clock
DEFINE ADC_SAMPLEUS 20 ' sample time in uS
'Variables
PulseWidth VAR BYTE
Freqtmp VAR BYTE
Frequency VAR Word
TRISIO = %00111011 ' all inputs except GPIO.2
ANSEL = %00000011 ' GPIO.0, GPIO.1 = analog, rest digital
CMCON0 = 7 ' comparator module disabled
Loop:
'Read Input Variables
ADCIN 0, PulseWidth 'Read analog in on GPIO.0
ADCIN 1, Freqtmp 'Read analog in on GPIO.1
Frequency = Freqtmp * 100 'Make Freq = 0-25,500hz in 100hz intervals
'Send Pulse
HPWM 1, PulseWidth, Frequency 'Send PWM with variable Duty and Frequency PinC.2 on 16f677A
Pause 500
goto Loop 'Do it forever
Note: The minimum frequency with HPWM running at 20MHz is ~1,221hz, so
you might get odd action on CCP1 once the A/D input falls below ~255mV.
Bookmarks