; Memory used = 1067 bytes out of 2048 ; http://eleclabyrinth.blog.fc2.com/blog-entry-128.html #picaxe 08m2 #NO_DATA ;I/0 symbol MODE_SW = pinC.3 ; 1:log mode 0:volt meter symbol ADCin1 = C.4 ; ch1 symbol ADCin2 = C.2 ; ch2 symbol ADCin3 = C.1 ; ch3 ; symbols symbol Voffset_ch1 = 10 ; voltage offset.(@0V) Change! ; 10 = 0LSB +-9LSB ; 1-19 --> -9 to +9 symbol Voffset_ch2 = 12 ; voltage offset.(@0V) Change! symbol Voffset_ch3 = 11 ; voltage offset.(@0V) Change! symbol Vgain_ch1 = 1000 ; Current adjustment Change! ; 1000 = 100.0% +-6.3% ; 93.7-106.3 --> 937-1063 symbol Vgain_ch2 = 1000 ; Current adjustment Change! symbol Vgain_ch3 = 1000 ; Current adjustment Change! symbol ST = 24 ; ADC sampling times 12-62 Even ??=200ms symbol LI = 5 ; Logging interval 1-60(s) symbol work_w0 = w0 symbol work_w1 = w1 symbol work_w2 = w2 symbol work_w5 = w9 symbol work_w3 = w3 ;symbol work_w4 = w4 symbol V1 = w5 ; ch1 symbol V2 = w6 ; ch2 symbol V3 = w10 ; ch3 symbol OV_ch1 = b14 ; over voltage ch1 symbol OV_ch2 = b15 ; over voltage ch2 symbol OV_ch3 = b17 ; over voltage ch3 symbol MODE = b16 ; disiplay mode symbol time_work0 = w13 ; ; ********************************************************** ;initialize pullup %00000 ;bit4 - bit0 = C.4 - C.0 ; C.0 pin is output only, so cannot have pullup. fvrsetup FVR4096 adcconfig %011 ; ADC Vref- = 0V, Vref+ = FVR hsersetup B38400_4, %10010 ;38400 baud, inverted TXD, disable hserin hserout 0,(cr) hserout 0,("\033[108A") ; ESC[108A up 108 line hserout 0,("\033[2J") ; ESC[2J CLS MODE = MODE_SW time_work0 = time + LI main: ;toggle C.1 ;for debug if time > 65415 then ; 65535-120s timer overflow end endif ;RDadc work_w1 = 0 work_w2 = 0 work_w5 = 0 for work_w3 = 1 to ST fvrsetup FVR4096 readadc10 ADCin1,work_w0 work_w1 = work_w1 + work_w0 ; ch1 * ST fvrsetup FVR1024 readadc10 ADCin2,work_w0 work_w2 = work_w2 + work_w0 ; ch2 * ST fvrsetup FVR4096 readadc10 ADCin3,work_w0 work_w5 = work_w5 + work_w0 ; ch3 * ST next work_w3 ; divide by ST work_w0 = ST / 2 work_w1 = work_w1 + work_w0 / ST ; ch1 work_w2 = work_w2 + work_w0 / ST ; ch2 work_w5 = work_w5 + work_w0 / ST ; ch3 ; check over voltage if work_w1 >= 1023 then OV_ch1 = 1 else OV_ch1 = 0 endif if work_w2 >= 1023 then OV_ch2 = 1 else OV_ch2 = 0 endif if work_w5 >= 1023 then OV_ch3 = 1 else OV_ch3 = 0 endif ; offset work_w3 = Voffset_ch1 if work_w3 > 10 then ; + offset work_w0 = work_w3 - 10 if work_w1 < work_w0 then V1 = 0 else V1 = work_w1 - work_w0 ; ch1 - offset endif elseif work_w3 < 10 then ; - offset work_w0 = 10 - work_w3 V1 = work_w1 + work_w0 ; ch1 + offset else V1 = work_w1 ; ch1 end if work_w3 = Voffset_ch2 if work_w3 > 10 then ; + offset work_w0 = work_w3 - 10 if work_w2 < work_w0 then V2 = 0 else V2 = work_w2 - work_w0 ; ch2 - offset endif elseif work_w3 < 10 then ; - offset work_w0 = 10 - work_w3 V2 = work_w2 + work_w0 ; ch2 + offset else V2 = work_w2 ; ch2 end if work_w3 = Voffset_ch3 if work_w3 > 10 then ; + offset work_w0 = work_w3 - 10 if work_w5 < work_w0 then V3 = 0 else V3 = work_w5 - work_w0 ; ch3 - offset endif elseif work_w3 < 10 then ; - offset work_w0 = 10 - work_w3 V3 = work_w5 + work_w0 ; ch3 + offset else V3 = work_w5 ; ch3 end if ;Gain_ADJ work_w3 = Vgain_ch1 ;10bit if work_w3 > 1000 then ; + gain work_w0 = work_w3 - 1000 ; 1-63 6bit work_w1 = V1 * work_w0 + 500 / 1000 ; (ch1-offset)*gain V1 = V1 + work_w1 elseif work_w3 < 1000 then ; - gain work_w0 = 1000 - work_w3 work_w1 = V1 * work_w0 + 500 / 1000 ; (ch1-offset)*gain V1 = V1 - work_w1 end if work_w3 = Vgain_ch2 ;10bit if work_w3 > 1000 then ; + gain work_w0 = work_w3 - 1000 ; 1-63 6bit work_w1 = V2 * work_w0 + 500 / 1000 ; (ch2-offset)*gain V2 = V2 + work_w1 elseif work_w3 < 1000 then ; - gain work_w0 = 1000 - work_w3 work_w1 = V2 * work_w0 + 500 / 1000 ; (ch2-offset)*gain V2 = V2 - work_w1 end if work_w3 = Vgain_ch3 ;10bit if work_w3 > 1000 then ; + gain work_w0 = work_w3 - 1000 ; 1-63 6bit work_w1 = V3 * work_w0 + 500 / 1000 ; (ch3-offset)*gain V3 = V3 + work_w1 elseif work_w3 < 1000 then ; - gain work_w0 = 1000 - work_w3 work_w1 = V3 * work_w0 + 500 / 1000 ; (ch3-offset)*gain V3 = V3 - work_w1 end if ; V1 = V1 * 4 ; * 4(mV) ;V2 = V2 * 1 ; * 1(mV) V3 = V3 * 4 ; * 4(mV) ; for debug ;time_work0 = time ;debug ;goto main ; display mode work_w0 = MODE_SW if work_w0 != MODE then ; home and CLS MODE = work_w0 hserout 0,(cr) hserout 0,("\033[108A") ; ESC[108A up 108 line hserout 0,("\033[2J") ; ESC[2J CLS time_work0 = time + LI end if if MODE = 0 then ; volt meter goto Volt_meter else ; log mode goto Log_mode end if Volt_meter: hserout 0,("\033[?25l") ; ESC[?25l Cursor off hserout 0,("\033[3A") ; ESC[3A up 3 line if OV_ch1 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif hserout 0,("ch1 ") work_w0 = V1 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V1 / 100 % 10 hserout 0,(#work_w0) work_w0 = V1 /10 % 10 hserout 0,(#work_w0) work_w0 = V1 % 10 ; 4mV hserout 0,(#work_w0) ; 4mV hserout 0,("v") hserout 0,(cr,lf) if OV_ch2 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif hserout 0,("ch2 ") work_w0 = V2 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V2 / 100 % 10 hserout 0,(#work_w0) work_w0 = V2 /10 % 10 hserout 0,(#work_w0) work_w0 = V2 % 10 ; 1mV hserout 0,(#work_w0) ; 1mV hserout 0,("v") hserout 0,(cr,lf) if OV_ch3 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif hserout 0,("ch3 ") work_w0 = V3 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V3 / 100 % 10 hserout 0,(#work_w0) work_w0 = V3 /10 % 10 hserout 0,(#work_w0) work_w0 = V3 % 10 ; 4mV hserout 0,(#work_w0) ; 4mV hserout 0,("v") hserout 0,(cr,lf) hserout 0,("\033[37m") ; ESC[37m, white hserout 0,("\033[?25h") ; ESC[?25l Cursor on goto main Log_mode: hserout 0,("\033[?25l") ; ESC[?25l Cursor off if OV_ch1 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif work_w0 = V1 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V1 / 100 % 10 hserout 0,(#work_w0) work_w0 = V1 /10 % 10 hserout 0,(#work_w0) work_w0 = V1 % 10 ; 4mV hserout 0,(#work_w0) ; 4mV hserout 0,(" ") if OV_ch2 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif work_w0 = V2 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V2 / 100 % 10 hserout 0,(#work_w0) work_w0 = V2 /10 % 10 hserout 0,(#work_w0) work_w0 = V2 % 10 ; 1mV hserout 0,(#work_w0) ; 1mV hserout 0,(" ") if OV_ch3 = 1 then hserout 0,("\033[31m") ; ESC[31m, red else hserout 0,("\033[37m") ; ESC[37m, white endif work_w0 = V3 / 1000 hserout 0,(#work_w0) hserout 0,(".") work_w0 = V3 / 100 % 10 hserout 0,(#work_w0) work_w0 = V3 /10 % 10 hserout 0,(#work_w0) work_w0 = V3 % 10 ; 1mV hserout 0,(#work_w0) ; 1mV hserout 0,(cr,lf) hserout 0,("\033[37m") ; ESC[37m, white hserout 0,("\033[?25h") ; ESC[?25l Cursor on Log_interval: if time > time_work0 then let time_work0 = time_work0 + LI goto main elseif MODE_SW = 0 then goto main else goto Log_interval endif