'jleblanc 10.30.05: control DC motor speed with pulsout command at 20mHz
' Connect a POT at A0 (assumes 0-1023 output) and connect D2 to
'TIP120 transistor to control DC motor. Makes the motor whine in my
'case. Note also that in the pulsout command dividing adcVar by a bigger
'number makes the motor go slower. The less you divide adcVar by,
'the faster the motor will go.
' 10-bit A/D conversion
' Connect analog input to channel-0 (RA0)
DEFINE OSC 20
' Define ADCIN parameters
' Set number of bits in result
DEFINE ADC_BITS 10
' Set clock source (3=rc)
DEFINE ADC_CLOCK 3
' Set sampling time in microseconds
DEFINE ADC_SAMPLEUS 10
adcVar VAR WORD ' Create variable to store result
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1
ADCON1 = %10000010
PAUSE 500 ' Wait .5 second
main:
ADCIN 0, adcVar ' Read channel 0
PULSOUT portd.2, adcVar/2
GOTO main