Offsetting input voltage in PICAXE-08M2 MCU

Thread Starter

Khisraw

Joined Nov 14, 2020
56
Hi,
I am connecting a sensor to PICAXE08M2 MCU. The sensor is read in pin C.4 and when it is off is 1.8V and 5V when it is fully ON. I need to offset the 1.8V. I need to write the codes in Basic. The ADC is 8 bit and the maximum value would be 255. My codes are below.

Main:
Readadc C.1, w0
Readadc C.4,w1 **** This needs to be offset.
w1 = w1-110
w2 = w0+w1
if w2 > 300 THEN
goto Change_output
end if
pause 200
goto Main


Change_output:

toggle C.0
pause 2000
goto Main

When both sensors are ON, it should generate and output.

Problem: When I try to do it like above, it goes to negative hence generating a 650000 in the W1 and of course it doesn't work.

Can someone tell me how to offset the voltage?
 

ericgibbs

Joined Jan 29, 2010
18,840
hi K,
If I follow your description correctly.?
Your Vref is 5V and ADC max count is 255.

So for (1.8/5)*255 = ~92 Counts, so why are you subtracting 110 counts.?

110 is 2.15Volts.

E
 
Top