{"id":374,"date":"2013-11-12T14:02:42","date_gmt":"2013-11-12T14:02:42","guid":{"rendered":"http:\/\/www.megalithia.com\/?p=374"},"modified":"2017-03-30T18:36:35","modified_gmt":"2017-03-30T18:36:35","slug":"how-to-measure-battery-capacity","status":"publish","type":"post","link":"https:\/\/www.richardmudhar.com\/blog\/2013\/11\/how-to-measure-battery-capacity\/","title":{"rendered":"how to measure AA battery capacity"},"content":{"rendered":"<p>Poundland in the UK sell batteries branded by Kodak, but the cheapest ones are zinc chloride. I thought ZnCl has gone out of use decades ago, but it is surprising how often people are penny-wise and pound foolish. Particularly in pound shops \ud83d\ude09<\/p>\n<figure id=\"attachment_378\" aria-describedby=\"caption-attachment-378\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_zncl_P1060126.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-378 size-medium\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_zncl_P1060126-225x300.jpg?resize=225%2C300\" alt=\"Cheap Poundland batteries are in fact twice as dear to use!\" width=\"225\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_zncl_P1060126.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_zncl_P1060126.jpg?resize=624%2C832&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_zncl_P1060126.jpg?w=768&amp;ssl=1 768w\" sizes=\"auto, (max-width: 225px) 85vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-378\" class=\"wp-caption-text\">Cheap Poundland batteries are in fact twice as dear to use&#8230;<\/figcaption><\/figure>\n<p>So I am looking to make something to track the discharge of a battery. This is also useful to qualify NiMH and NiCd batteries &#8211; these fade with time and it is good to know what sort of capacity is left.<\/p>\n<figure id=\"attachment_379\" aria-describedby=\"caption-attachment-379\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_alk_P1060128.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-379 size-medium\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_alk_P1060128-225x300.jpg?resize=225%2C300\" alt=\"...as the expensive ones!\" width=\"225\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_alk_P1060128.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_alk_P1060128.jpg?resize=624%2C832&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_alk_P1060128.jpg?w=768&amp;ssl=1 768w\" sizes=\"auto, (max-width: 225px) 85vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-379\" class=\"wp-caption-text\">&#8230;as the expensive ones!<\/figcaption><\/figure>\n<p>Every minute it reports the voltage and current from the batteries running through a 2.5V torch bulb, the third bulb is maintained at 2.5V to provide a reference. It transmits the signal using radio to a datalogger. I got a camera to take a picture every 15 minutes, as a video the results are reasonably clear. A picture tells a thousand words &#8211; the Zinc Chloride batteries are crap<\/p>\n<p><iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/OZtlIhtksaw?rel=0&amp;showinfo=0\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>The left-hand bulb is powered by the &#8216;cheap&#8217; battery that Poundland sell for 9p, the middle is powered by the &#8216;dearer&#8217; alkalines they sell at about 17p.<\/p>\n<figure id=\"attachment_375\" aria-describedby=\"caption-attachment-375\" style=\"width: 215px\" class=\"wp-caption alignright\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-375 size-full\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_abcschem.gif?resize=215%2C373\" alt=\"Bulb measurement schematic\" width=\"215\" height=\"373\" \/><figcaption id=\"caption-attachment-375\" class=\"wp-caption-text\">Bulb measurement schematic<\/figcaption><\/figure>\n<p>I have a <a title=\"How to use the OpenKontrolGateway for Data Logging\" href=\"http:\/\/www.richardmudhar.com\/blog\/2012\/11\/how-to-use-openkontrolgateway-data-logging\/\">Ciseco OpenKontrol Gateway<\/a> as a datalogger. It stores data to a SD card, but there is no law saying you couldn&#8217;t send it to some kind of IoT host like Xively. So all I need is the interface to the batteries to track the voltage and current; I used a 2.5V torch bulb for the load because it does not seem unreasonable to me to expect batteries to be used in a torch, I use two batteries in series, which seems to be the most common configuration in a torch. On the way to ground I use a 1 ohm resistor so I can measure between ground and the top of the bulb the battery voltage and between the resistor and ground the voltage corresponding to the current. Using 1 ohm makes the calculation easy, and also drops about 0.3V so the bulb is run at 2.7V at the start.<\/p>\n<p>Now if you are looking to do this in a big way then these guys at <a href=\"http:\/\/www.batteryshowdown.com\/index.html\">Battery Showdown<\/a> are doing this is a more rigorous way but their hardware is dearer. I&#8217;m also not absolutely sure that a constant current discharge is typical of many loads. something like a digital camera with a switch mode PSU actually increases its peak load with decreasing battery voltage because it is more a constant power device and needs to draw more current at a lower voltage to run the focusing bits. Something with a linear voltage regulator is a constant current to the dropout voltage of the regulator, but you don&#8217;t often see linear regulators in battery-powered kit.<\/p>\n<p>The bulb isn&#8217;t ideal either, with a varying resistance with temperature, so I&#8217;d probably favour using resistive loads, and getting four\/five battery channels instead of two. But the visuals were great for the video.<\/p>\n<p>If you have a PC that can take RS232 then simply wire the output of the PIC to the PC serial port via a Max232 chip or single transistor inverter if you don&#8217;t need the radio connection. Since I have the datalogger logging other sensors it seems easy enough to use it as is.<\/p>\n<p>I used a PIC16F870 that has five A\/D channels &#8211; this gives me two battery channels. Each battery channel has one A\/D port connected to A in the diagram, another one to B and 0V is connected to C. The voltage at B is the same as the current since R is 1\u03a9 and the voltage at A is the battery voltage itself. The 10-bit A\/D converter goes up to 1024, by setting the reference voltage to be the PIC power supply at the high end and PIC ground at the low end I made the maths easier by setting the PIC supply voltage to 5.12 V (this is within the PIC operational voltage spec of 4 to 5.5V) in which case a straight divide by two gives V in * 100, and matches the requirements acceptably.<\/p>\n<p>Doing this for the Poundland batteries shows the difference between the alkaline and the ZnCl batteries<\/p>\n<figure id=\"attachment_377\" aria-describedby=\"caption-attachment-377\" style=\"width: 478px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-377 size-full\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_kodak_dur.gif?resize=478%2C457\" alt=\"alkalines give about three times the runtime than ZnCl\" width=\"478\" height=\"457\" \/><figcaption id=\"caption-attachment-377\" class=\"wp-caption-text\">alkalines give about three times the runtime than ZnCl<\/figcaption><\/figure>\n<p>If we take the service life as down to 2V from 3V initially,\u00a0then you get 1.7 hours from the cheap ones and 5.8 hours from the alkalines.Alkaline cost\/hr is 17*2\/5.8=5.9p\/hr and the cheap batteries cost 9*2\/1.7=10.6p\/hr.<\/p>\n<p>As a result you pay about twice as much to run something using the cheap Poundland batteries, and you get to replace the batteries three times as often. Saving money therefore costs you a fortune in aggravation and generates more waste. You also have this sort of problem if you don&#8217;t pay attention and leave the used batteries in too long.<\/p>\n<figure id=\"attachment_380\" aria-describedby=\"caption-attachment-380\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_dcell_P1060135.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-380 size-medium\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_dcell_P1060135-225x300.jpg?resize=225%2C300\" alt=\"cheap batteries consume the zinc outer casing, leading to this\" width=\"225\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_dcell_P1060135.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_dcell_P1060135.jpg?resize=624%2C832&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_dcell_P1060135.jpg?w=768&amp;ssl=1 768w\" sizes=\"auto, (max-width: 225px) 85vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-380\" class=\"wp-caption-text\">cheap batteries consume the zinc outer casing, leading to this<\/figcaption><\/figure>\n<p>The device offers an insight into the capacity of rechargeable batteries which is the more useful feature of it.<\/p>\n<figure id=\"attachment_397\" aria-describedby=\"caption-attachment-397\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-397 size-full\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_nicad.gif?resize=636%2C534\" alt=\"a very old pair of 500mAh nicads and a pair of Uniross 2300mAh NiMh\" width=\"636\" height=\"534\" \/><figcaption id=\"caption-attachment-397\" class=\"wp-caption-text\">a very old pair of 500mAh nicads and a pair of Uniross 2300mAh NiMh<\/figcaption><\/figure>\n<p>I am not really sure I understand the pathology behind the second wind the NiMH cells seem to have. I&#8217;d discard it as a fault in reading except that &#8211; the current shows the bulb did not blow or become loose, and the A\/D and voltage reference is multiplexed, so the error should have shown elsewhere.\u00a0 will repeat this and see if it happens again &#8211; probably not as this battery has been totally flattened so it is not the same battery.<\/p>\n<p>For rechargeables I will modify this rig to take four individual cells and discharge through four resistors.\u00a0That way I don&#8217;t back-charge any weak cells, and I don&#8217;t need to measure the current as the terminal voltage and Ohms Law will tell me the current. If I run 2.7\u03a9 I will run about 440mA.<\/p>\n<p>&nbsp;<\/p>\n<h4>\u00a0Schematic<\/h4>\n<figure id=\"attachment_381\" aria-describedby=\"caption-attachment-381\" style=\"width: 512px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_battery_tester.gif\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-381\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2013\/11\/1311_battery_tester.gif?resize=512%2C356\" alt=\"\" width=\"512\" height=\"356\" \/><\/a><figcaption id=\"caption-attachment-381\" class=\"wp-caption-text\">PIC battery tester schematic<\/figcaption><\/figure>\n<p>JAL code<\/p>\n<p>The <a href=\"http:\/\/en.wikipedia.org\/wiki\/JAL_%28compiler%29\" target=\"_blank\">JAL<\/a> code for the PIC is <a href=\"http:\/\/www.oaktreelabs.co.uk\/blog\/wp-content\/uploads\/2013\/11\/1311_datalogger_v06.jal_.txt\">1311_datalogger_v06.jal<\/a><\/p>\n<pre>-- JAL 2.4i\r\n-- derived from univ-sensor_v06\r\n-- Datalogger\r\n-- adjust power supply to 5.12V using the LM317 regulator.\r\n-- internal Vref = VCC = 5.12V\r\n-- Can just divide ADC by 2 and shift dec point by two places\r\n-- v06 12 Nov 2013 RM\r\n-- CC BY-SA 3.0\r\n-- http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/\r\n-- serial port designed for use with a Ciseco XBBO board and radio ( Google it)\r\n-- can also use w\/o radio via a Max232 or a FTDI adapter instead\r\n-- radio is powered down while ADC measurement made to avoid loading regulator voltage\r\n\r\ninclude 16f870\r\npragma target clock\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4_000_000\r\npragma target osc\u00a0\u00a0\u00a0 HS\u00a0\u00a0 ; use a 4MHz crystal or resonator\r\npragma target WDT\u00a0\u00a0\u00a0 ENABLED\r\npragma target PWRTE\u00a0 ENABLED\r\npragma target BROWNOUT\u00a0\u00a0\u00a0 ENABLED\r\npragma target LVP\u00a0\u00a0\u00a0 DISABLED\r\npragma target CP\u00a0\u00a0\u00a0 DISABLED\r\npragma target CPD\u00a0\u00a0\u00a0 DISABLED\r\n-- HS, -BOD, ,-LVP, -WDT, -CP\u00a0 = 0x3F22\r\n;pragma target fuses\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0x2007\r\n\r\ninclude pic_general\r\ninclude print\r\ninclude format\r\n\r\n-- set all interrupt sources disabled\r\n;INTCON = 0\r\n\r\n-- ADC includes delays so don't include this myself\r\n\r\n-- V2 delay's\r\n-- include delay_any_mc\r\n\r\n-- more delay functions\r\n-- include extradelay\r\n\r\n-- the analogue pins\r\npin_a0_direction = input\r\npin_a1_direction = input\r\npin_a2_direction = input\r\npin_a3_direction = input\r\n-- there is no a4 analogue channel\r\npin_a5_direction = input\r\n\r\npin_c7_direction = input\r\npin_c5_direction = output\r\npin_c6_direction = output\r\n\r\npin_A4_direction = output\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; this is open drain so 3V3 pullup comes from XRF\r\nalias xrf_sleep is pin_A4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; pull this low to start the XRF, let go and float up to enter sleep\r\nxrf_sleep=low\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; must enable with ATSM2\r\n\r\n-- now configure ADC\u00a0 (this is a 10-bit ADC)\r\n\r\nconst bit ADC_HIGH_RESOLUTION = true\r\nconst byte ADC_NCHANNEL = 1\r\nconst byte ADC_NVREF = ADC_NO_EXT_VREF\r\ninclude adc\r\nadc_init()\r\n\r\n-- ok, now setup serial, we'll use this\r\n-- to get ADC measures\r\n\r\n-- all this is because the 16f870.inc file is not right for serial hardware\u00a0 8\/5\/13\r\nalias RCIF IS PIR1_RCIF\r\nalias TXIF IS PIR1_TXIF\r\nalias BRGH IS TXSTA_BRGH\r\nalias RCIE IS PIE1_RCIE\r\nalias TXIE IS PIE1_TXIE\r\nalias TXEN IS TXSTA_TXEN\r\nalias TRMT IS TXSTA_TRMT\r\nalias SPEN IS RCSTA_SPEN\r\nalias OERR IS RCSTA_OERR\r\nalias CREN IS RCSTA_CREN\r\n-- end of\r\n-- all this is because the 16f870.inc file is not right for serial hardware\r\n\r\nalias PEIE IS INTCON_PEIE\r\nalias TMR1IE IS PIE1_TMR1IE\r\nalias CCP1IF IS PIR1_CCP1IF\r\n\r\nOPTION_REG = 0b00001111 ; PS asllocated to WDT and slowest rate selected (20ms*128)\r\nPEIE = high\r\nTMR1IE = high\r\nT1CON=0b00110001\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; set timer 1 running internal osc 8xprescaled\r\nCCP1CON=0b00001011\u00a0\u00a0\u00a0\u00a0\u00a0 ; reset tmr1 on match, kicks off an A\/D conversion\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; these next values seem to call a period of 10s from previous project\r\nCCPR1H=244\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; decimal\r\nCCPR1L=36\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; decimal\r\n-- so count is 244*256+36 = 62500 At 4MHz each tick is 1uS, prescsaled by 8 to 8uS ticks.\r\n--\r\nconst byte cyclesmax=60*2\u00a0\u00a0 -- how many times to count 0.5s ticks\r\n\r\nvar word mincounter = 0\r\n;var byte lastTMR0=0\r\n;TMR0=0\u00a0\u00a0 -- clear at start\r\n\r\n-- ok, now setup serial;\r\nconst serial_hw_baudrate = 9600\r\nconst bit usart_hw_serial = TRUE\r\nconst bit lowspeed=true\r\ninclude print\r\ninclude serial_hardware\r\nserial_hw_init()\r\n\r\nconst byte booted[] = \"aVVSTARTED--\"\r\nconst byte prefix[] = \"aVV\"\r\nconst byte line1[] = \"+++\"\r\nconst byte line2[] = \"ATSM2r\"\r\nconst byte line3[] = \"ATACr\"\r\nconst byte line4[] = \"ATDNr\"\r\nconst byte line5[] = \"ATID0AFFr\"\r\nconst byte vpfx[]= \"VLT\"\r\n\r\nprocedure WaitOnOk() IS\r\n-- state machine - aim is to hang and\r\n-- if this doesn't get to 2 the WDT will start things over after 2 sec\r\n-- if it gets to 2 it clrwdt anbd returns\r\n\r\nvar byte state=0\r\nasm clrwdt\r\nwhile state !=2 loop\r\nif serial_hw_data_available then\r\n\u00a0\u00a0 if state==0 &amp; serial_hw_data == \"O\" then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 state=1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; this is the only way to get to state 1\r\n\u00a0\u00a0 end if\r\n\u00a0\u00a0 if (state == 1) &amp; (serial_hw_data == \"K\") then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 state=2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 state=0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; because O was followed by something that wasn't K\r\n\u00a0\u00a0 end if\r\nend if\r\nasm clrwdt\r\nend loop\r\n\r\nend procedure\r\n\r\nprocedure justify(word IN myval)\u00a0 IS\r\n-- value is going to be 0..1024 (in reality 0..512)\r\n-- hundreds are integers, ie 2 d.p.\r\n-- assumes radio is up and running\r\n\u00a0 format_word_dec(serial_hw_data,myval,3,2)\u00a0 -- 0\u00a0\u00a0 .23\r\n\u00a0 serial_hw_data=\"-\"\r\nend procedure\r\n\r\nfunction get_volts() return bit\u00a0 is\r\n\u00a0 var word reading1\r\n\u00a0 var word reading2\r\n\u00a0 var word reading3\r\n\u00a0 var word reading4\r\n\u00a0 var word reading5\r\n\u00a0 asm clrwdt\r\n\u00a0 -- get ADC result, high resolution\r\n\u00a0 reading1 = adc_read_high_res(0)\/2\r\n\u00a0 asm clrwdt\r\n\u00a0 -- get ADC result, high resolution\r\n\u00a0 reading2 = adc_read_high_res(1)\/2\r\n\u00a0 asm clrwdt\r\n\u00a0 -- get ADC result, high resolution\r\n\u00a0 reading3 = adc_read_high_res(2)\/2\r\n\u00a0 asm clrwdt\r\n\u00a0 -- get ADC result, high resolution\r\n\u00a0 reading4 = adc_read_high_res(3)\/2\r\n\u00a0 asm clrwdt\r\n\u00a0 -- get ADC result, high resolution\r\n\u00a0 reading5 = adc_read_high_res(4)\/2\r\n\u00a0 asm clrwdt\r\n\u00a0 -- send it back through serial\r\n\u00a0 xrf_sleep=low\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- start the radio a little before the data will be sent.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- may want to change the LLAP prefix and comma del if not using radio\r\n\u00a0 delay_100ms(2)\r\n\u00a0 asm clrwdt\r\n\u00a0 print_string(serial_hw_data,prefix)\r\n\u00a0 print_string(serial_hw_data,vpfx)\r\n\u00a0 serial_hw_data=\"A\"\r\n\u00a0 justify(reading1)\r\n\u00a0 asm clrwdt\r\n\u00a0 delay_100ms(5)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- no need for this dela if going straight out on serial\r\n\u00a0 print_string(serial_hw_data,prefix)\r\n\u00a0 print_string(serial_hw_data,vpfx)\r\n\u00a0 serial_hw_data=\"B\"\r\n\u00a0 justify(reading2)\r\n\u00a0 asm clrwdt\r\n\u00a0 delay_100ms(5)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- allows the LLAP data to be received properly\r\n\u00a0 asm clrwdt\r\n\u00a0 print_string(serial_hw_data,prefix)\r\n\u00a0 print_string(serial_hw_data,vpfx)\r\n\u00a0 serial_hw_data=\"C\"\r\n\u00a0 justify(reading3)\r\n\u00a0 asm clrwdt\r\n\u00a0 print_string(serial_hw_data,prefix)\r\n\u00a0 print_string(serial_hw_data,vpfx)\r\n\u00a0 serial_hw_data=\"D\"\r\n\u00a0 justify(reading4)\r\n\u00a0 asm clrwdt\r\n\u00a0 delay_100ms(5)\r\n\u00a0 asm clrwdt\r\n\u00a0 print_string(serial_hw_data,prefix)\r\n\u00a0 print_string(serial_hw_data,vpfx)\r\n\u00a0 serial_hw_data=\"E\"\r\n\u00a0 justify(reading5)\r\n\u00a0 asm clrwdt\r\n\u00a0 delay_100ms(2)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- let the signal be transmitted and buffer empty\r\n\u00a0 xrf_sleep=high\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- stop the radio ftre the original data sent\r\n\u00a0 return true\r\n\r\nend function\r\n\r\n-- MAIN PROGRAM START\r\n\r\nasm clrwdt\r\nasm sleep\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; use the WDT to delay about 2s to\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; boot the sensor\u00a0 and radio\r\nasm clrwdt\r\n\r\n-- now initialise the XRF to the system network ID and enable sleep mode\r\n-- clear out any pre-existing RX buffer\r\nvar byte rxd\r\nwhile serial_hw_data_available loop -- check if data is ready for us\r\n\u00a0 rxd = serial_hw_data\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- get the data\r\nend loop\r\nrxd=\" \"\r\n\r\nif true then\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; loop is simply to enable\/disable\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; if you have no radio then use if false then\r\nasm clrwdt\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; this setup routine for testing\r\nxrf_sleep=low\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; setup the radio using AT commands\r\nprint_string(serial_hw_data, line1) ; send +++\r\nWaitOnOk\r\nprint_string(serial_hw_data, line5) ; change network with ATID0AFF\r\ndelay_100ms(1)\r\nprint_string(serial_hw_data, line2) ; enable sleep mode with ATSM2\r\ndelay_100ms(1)\r\nprint_string(serial_hw_data, line3) ; and use it - send commit\r\ndelay_100ms(1)\r\nprint_string(serial_hw_data, line4) ; ATDN we are done configuring\r\ndelay_100ms(10)\r\nprint_string(serial_hw_data,booted)\r\ndelay_100ms(2)\r\nxrf_sleep=high\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- power down the radio\r\nend if\r\n\r\nforever loop\r\n\r\nasm clrwdt\r\nif CCP1IF then\r\n\u00a0\u00a0 CCP1IF=false;\r\n\u00a0\u00a0 mincounter=mincounter+1\r\nend if\r\n\r\nif mincounter &gt;= cyclesmax-1 then\r\n\u00a0\u00a0 mincounter=0\r\n\u00a0\u00a0 var bit b = get_volts()\r\nend if\r\n\r\nend loop<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Poundland in the UK sell batteries branded by Kodak, but the cheapest ones are zinc chloride. I thought ZnCl has gone out of use decades ago, but it is surprising how often people are penny-wise and pound foolish. Particularly in pound shops \ud83d\ude09 So I am looking to make something to track the discharge of &hellip; <a href=\"https:\/\/www.richardmudhar.com\/blog\/2013\/11\/how-to-measure-battery-capacity\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;how to measure AA battery capacity&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[57],"tags":[238,8],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-battery","tag-power-supply"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5aOO7-62","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/comments?post=374"}],"version-history":[{"count":3,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":2848,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/374\/revisions\/2848"}],"wp:attachment":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}