'airride based on veh speed, 4 ride hights for 4 different speed zones 423 byts. PIX 20X2 TEST>>>>>!
'This code uses the count command to count the low to high transitions over 1 second of time(Hz) to determin
'speed.
main:
let dirsc = %00000000 'set portC as inputs
let dirsb = %10111111 'set portB as out puts
let adcsetup = %0000000111000100
symbol airtank=b1
symbol front=b2
symbol rear=b3
symbol prevspeed=b5
symbol currentspeed=b6
symbol difference=b7
symbol manual=b8
readadc 9, airtank 'read adc1 airtank psi
readadc 8, front 'adc2 front height input
readadc 7, rear 'adc3 rear height input
readadc 3, manual 'manual setting
prevspeed = currentspeed
count 6, 1000, currentspeed 'count low to high pulses over 1 second (raising edge)
select case airtank
case < 220 : high 1 ' Turn compressor on
case > 230 : low 1 ' Turn compressor off
end select
if airtank < 180 then flash_1 'if tank below 180 adc all output will stay low
if currentspeed >= prevspeed then
difference = currentspeed - prevspeed
else
difference = prevspeed - currentspeed
endif
if difference > 5 then flash_1
select case manual
case 55 to 155 goto flash_4 'maunal set ride height by switching input pin high
case 156 to 200 goto flash_3 'maunal set ride height by switching input pin high
case 201 to 255 goto flash_2
endselect 'maunal set ride height by switching input pin high
select case currentspeed
case 0 to 60 goto flash_5 'numbers are in Hz. Pulses over 1 seconds time
case 61 to 83 goto flash_4 '2 pulses per drive shaft turn
case 84 to 100 goto flash_3 '60 = 40mph, 84 = 55mph, 100 = 65mph
case 101 to 254 goto flash_2 '4 ride heights for 0 to 40, 40 to 55, 55 to 65 and 65+
endselect
flash_5:
if front < 170 then high b.2 'if adc is below 170 turn output 2 on
elseif front > 180 then low b.2 'adc count above 180 turn output 2 off
endif
if rear < 170 then high b.4 'if adc is below 170 turn output 4 on
elseif rear > 180 then low b.4 'adc count above 180 turn output 4 off
endif
if front > 180 then high b.3 'turn on output 3
endif
if rear > 180 then high b.5 'turn on output 5
endif
pause 1000 'pause for 1 sec
low 3 'turn off 3
low 5 'turn off 5
goto main 'start over
flash_1: 'from above
low b.2 'output 2 low
low b.3 'output 3 low
low b.4 'output 4 low
low b.5 'output 5 low
goto main 'start over
flash_2: 'from above
if front < 150 then high b.2 'if adc is below 150 turn output 2 on
elseif front > 160 then low b.2 'adc count above 160 turn output 2 off
endif
if rear < 150 then high b.4 'if adc is below 150 turn output 4 on
elseif rear > 160 then low b.4 'adc count above 160 turn output 4 off
endif
if front > 160 then high b.3
endif
if rear > 160 then high b.5
endif
pause 1000
low b.3
low b.5
goto main
flash_3: 'from above
if front < 130 then high b.2 'if adc is below 130 turn output 2 on
elseif front > 140 then low b.2 'adc count above 140 turn output 2 off
endif
if rear < 130 then high b.4 'if adc is below 130 turn output 4 on
elseif rear > 140 then low b.4 'adc count above 140 turn output 4 off
endif
if front > 140 then high b.3
endif
if rear > 140 then high b.5
endif
pause 1000
low b.3
low b.5
goto main
flash_4:
if front < 120 then high b.2 'if adc is below 130 turn output 2 on
elseif front > 130 then low b.2 'adc count above 140 turn output 2 off
endif
if rear < 120 then high b.4 'if adc is below 130 turn output 4 on
elseif rear > 130 then low b.4 'adc count above 140 turn output 4 off
endif
if front > 130 then high b.3
endif
if rear > 130 then high b.5
endif
pause 1000
low b.3
low b.5
goto main