emmett brown
- 11th July 2006, 01:42
I don't have the next to the last line right but I've tried quite a few things with no avail. Thanks much!
DEFINE OSC 4
PVAL VAR WORD
pval2 var word
b0 var word
b1 var word
DUTY VAR BYTE
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
Begin:
PVAL = 1000 ' Start with 1kHz
For duty = 64 To 250
hpwm 1, duty, pval
pause 1000
Next duty
duty = 60 ' 30% Duty-cycle
For pval = 1000 To 10000 Step 100 'Increments of 100. Change as needed
hpwm 1, duty, pval
pause 1000
Next pval
TRISA = 255 ' Set PORTA to all input
ADCON1 = 2 ' PORTA is analog
ADCIN 0, B0 ' Read channel 0 to B0
pause 2000
TRISB = 255 ' Set PORTB to all input
ADCON1 = 2 ' PORTB is analog
ADCIN 1, B1 ' Read channel 1 to B1
if b0 < b1 then pval -1 'run pval backwards
if b0 >= b1 then begin
DEFINE OSC 4
PVAL VAR WORD
pval2 var word
b0 var word
b1 var word
DUTY VAR BYTE
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
Begin:
PVAL = 1000 ' Start with 1kHz
For duty = 64 To 250
hpwm 1, duty, pval
pause 1000
Next duty
duty = 60 ' 30% Duty-cycle
For pval = 1000 To 10000 Step 100 'Increments of 100. Change as needed
hpwm 1, duty, pval
pause 1000
Next pval
TRISA = 255 ' Set PORTA to all input
ADCON1 = 2 ' PORTA is analog
ADCIN 0, B0 ' Read channel 0 to B0
pause 2000
TRISB = 255 ' Set PORTB to all input
ADCON1 = 2 ' PORTB is analog
ADCIN 1, B1 ' Read channel 1 to B1
if b0 < b1 then pval -1 'run pval backwards
if b0 >= b1 then begin