PUB getADC(chan) 'get ADC voltage value channel := chan 'save "channel"variable outa[cs1] := 1 'Set CS1 output= high - preset value outa[clk] := 1 'Set CLK output= high - preset clock pulse bf CS1 outa[cs1] := 0 'CS1 output low - start ADC outa[clk] := 0 command :=(%11000 + chan) << (32-5) 'command Start, Single, Chan(xx) repeat 5 'send 5 command bits - per Specification outa[sdo] := (command <-= 1) & 1 outa[clk] := 1 'clock the command bit outa[clk] := 0 outa[clk] := 1 'set CLK output= high - one clock pulse after Command = 5th Clock pulse outa[clk] := 0 'set CLK output= low - set sample and hold ADC value outa[clk] := 1 'set CLK output= high - one clock pulse after Command = 6th Clock pulse outa[clk] := 0 'set CLK output= low - end conversion = Null bit ADCvalue := 0 'clear work variable =0 repeat 12 'read conversion 12 data bits ADCvalue := (ADCvalue << 1) | ina[sdi] 'input ADC data bit outa[clk] := 1 'clock ADC data bit outa[clk] := 0 outa[clk] := 0 'just to be sure = 0 outa[cs1] := 1 'CS1 output high - end ADC outa[clk] := 0 return ADCvalue