Hey, thanks for taking the time to help.
here is what i am trying to do:
1. take the average of 10 voltage readings while the green light is on, then average it...then do the same with the red light.
2. I am then taking the ratio of the 2.
i am taking measurements infinitely
after i find my first ratio, i need to output the ratio as a pulse width modulation signal. the problem is, i want to continue the PWM while i am taking my next measurement. is there a way to send out the pwm while i am doing other things such as blinking lights and making calculations. here is what i have so far:
'Define ADCIN parameters
Define LOADER_USED 1
'Define ADC_BITS 8 ' Set number of bits in result
'Define ADC_CLOCK 3 ' Set clock source (3=rc)
'Define ADC_SAMPLEUS 50 ' Set sampling time in uS
G var PORTD.0
'CS var PORTA.1 'chip select sensors
R var PORTD.1
Green var byte
Red var byte
pH var byte
x var byte
out var byte
x=0
' TRISA = %00100001 'sets port A to inputs/outputs
' TRISC = %00000000 'sets port C to inputs/outputs
'ADCON1 =0
reset:
x=0
green_loop:
high g ' Turn green LED on/red off
low r
pause 50
' ADCin 0,green 'a/d converter
ph=ph+green 'voltage measured 10x and added into one number
x=x+1
if x<10 then green_loop
x=0
green=ph/10 'averages Green reading
ph=0
red_loop:
low g 'Turn red LED on/green off
high r
pause 50
' ADCin 0,red 'a/d converter
ph=ph+red 'voltage measured 10x and added into one number
x=x+1
if x<10 then red_loop
red=ph/10 'averages reading
out=green/red 'ration of green/red
ph=0
pwm PORTD.2,out,500 'outputs ratio as PWM signal
goto reset
Thanks, David
Bookmarks