Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:51 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM and HC-12 battery useage

     Page 1 of 3    
Author Message
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 04:26pm 22 Jun 2017
Copy link to clipboard 
Print this post

Hi,
I am trying to power a remote temperature sensor with two AA cells but appear to be only getting less than two day's life out of the batteries.
1) Is my circuit OK?
2) Would 3x AAAs be better?



The batteries are powering a MM (28 pin), an HC-12 and a DS18B20.
The remote code is below. It sends a simple NMEA sentence (with checksum) twice, then sleeps for 59 seconds. If the temperature is unchanged it goes straight back to sleep, otherwise it sends the new temperature (twice) then goes to sleep.
I can:
a) extend the sleep time (10 minutes is better but I wanted to see more readings whilst developing the code)
b) reduce the CPU speed
c) send the sentence only once and discard any erroneous transmission receipts
d) turn the power down on the HC-12 (a marginal(?) improvement at the risk of reducing range within the house)
3) which of these are likely to give most bang for the buck?

4) Is there anything else I can try and any improvements to the code??

Cheers,

Andrew



Dim Integer Chksum
Dim Float Temp, TempOld

TempOld = 0
Do 'The main loop - it never ends
Open "COM1:9600" As #1 'Com1 uses pins 21 and 22 for Tx and Rx repsectively
pause 250
SendTemp
Pause 250
Close #1
CPU SLEEP 59 'Seconds
Loop
End

Sub SendTemp
Local String Out$
Temp = TEMPR(16)
If Temp = TempOld then
Exit Sub
Else
TempOld = Temp
EndIf
Out$ = CRC$("$AGMTW,"+Str$(Temp)+",C")
Print Time$, Out$
Print #1,Out$
Print #1,Out$ 'Second time
End Sub 'SendTemp

FUNCTION CRC$(Txt$) 'AS String 'Returns the Txt$ passed to it with "*hh" added, where hh is the Hex checksum
Chksum = 0
FOR n = 2 TO LEN(Txt$) 'n=2 makes it skip the leading $
'If Mid$(Report$, n, 1) <> "," then
Chksum=Chksum XOR ASC(MID$(Txt$,n,1))
'EndIf
NEXT n
CRC$=Txt$+"*"+HEX$(Chksum,2)
END FUNCTION
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 04:37pm 22 Jun 2017
Copy link to clipboard 
Print this post

Have you set the HC-12 into low power mode.
I haven't done any tests but the datasheet has idle current of 16mA in the default mode compared with 80uA in FU2 mode

Using 3 AA cells will put the voltage higher than the micromite can handle.
2 cells has the voltage good for the micromite but marginal for the HC-12 as the voltage drops off.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:26pm 22 Jun 2017
Copy link to clipboard 
Print this post

Completely agree with Jim here. You need to connect the HC-12's 'SET' line to one of the MM I/O lines and use that to put the module to sleep. This is a LITTLE more tricky then most other modules that just use an EN(able) line to control the module.

In the HC-12, you have to:

1) Put the module into SETUP mode by pulling the 'SET' line low
2) Issue the command AT+SLEEP via the serial port
3) Return the 'SET' line high again

Current consumption of a sleeping HC-12 is about 22uA so says the datasheet.

To wake up a sleeping module, you have to pulse the 'SET' line low again(50mS should do it), then return the line high again and WAIT 200mS for the module to reset itself.

I plan to do some testing on this concept shortly, so I will be able to confirm this soon, as I have not actually ever slept an HC-12 module, but reading the datasheet, the above would appear to be the sequence.
Edited by Grogster 2017-06-24
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 09:50pm 22 Jun 2017
Copy link to clipboard 
Print this post

Thanks Jim and Grogster,
I'll certainly give it a go.

Do you have any experience of how long a MM should go with 2x AAs without the extra drain of the HC-12 (and DS1820)?

I haven't cracked changing the settings of the HC-12 yet (it worked with the default values - once I sorted out the Tx/Rx swap). I actually have two transmitting temperatures to the one receiver. I have yet to incorporate it into useful software but I will.

Thanks again, Andrew

 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 04:10am 23 Jun 2017
Copy link to clipboard 
Print this post

Page 15 of the Micromite User Manual gives some hints on reducing the sleep current of the Micromite. They might help.

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:16am 23 Jun 2017
Copy link to clipboard 
Print this post

  Andrew_G said  Do you have any experience of how long a MM should go with 2x AAs without the extra drain of the HC-12 (and DS1820)?


Not sure exactly, but if every joule of energy is important to make the batteries last as long as possible, I would be inclined to throttle back the MM to 5MHz with the CPU 5 command at the top of your code. This will drop the current consumption of the MM chip back to around 6mA or so vs 31mA or so at normal throttle. It does depend on exactly what you are doing to some extent, and 5MHz may be too slow, so you might need to throttle-up to 10MHz or so instead - all ahead slow instead of all ahead dead-slow.
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 02:25pm 23 Jun 2017
Copy link to clipboard 
Print this post

Thanks Geoff and Grogs. I have plenty of options to try out . . .
(I assume my circuit is OK except that I should connect all unused pins on the MM to Ground?)

Cheers,

Andrew
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:24pm 23 Jun 2017
Copy link to clipboard 
Print this post

I used to think that you should ground unused pins too, but I seem to recall someone saying that this was only a requirement for CMOS logic gates on discrete logic chips, so that a floating gate input does not cause the logic to do odd things.

With microcontrollers, I don't think you need to worry, and I have not bothered to connect unused pins to anything since I started using microcontrollers. I think it was the PICAXE forums who taught me that particular bit of knowledge.

IE: If your code never references the unused pins in any way, they will remain as high-impedance inputs(as set from power-up), and will have no effect. Even if they DO float up and down, the code won't care, as it totally ignores them if you never reference them anywhere.

That is my understanding, anyway. I am sure other members more in the know then me will correct that if I am in fact wrong, but I hope not!
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 06:59pm 23 Jun 2017
Copy link to clipboard 
Print this post

IIRC some time ago I was trying to set a mx170 up with the most power saving trying various regulators only two pins in use and I found that there was a very marginal increase in power consumption when all unused pins were grounded.
Graeme
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 07:55pm 11 Aug 2017
Copy link to clipboard 
Print this post

Hi all,
I have been distracted over the last two months but I am still trying to minimise consumption on my remote temperature-sensing MM. I believe I have included all of your suggestions in the code below (if not pl. let me know) but I still have a sleep current of 0.5mA - much better than before but is it the best I can achieve?.
Is the DS18B20 causing this?

The circuit is the same as above except that pin 5 of the HC-12 now goes to pin 14 of the MM.

Thanks again,

Andrew


'HC-12 Remote ID3.bas
'Uses a 28 pin MM170 to take temperature readings via a DS18B20.
' An HC-12 is used to transmit the readings to a base station which displays the readings from several remote stations.
' Each remote station is identified by an ID - this code is for station No. 3.
'
'Notes to self:
'Don't forget the <CR><LF> at the end of NMEA sentences
'I use zzz to flag code I need to check
'Steps to reduce power consumption:
' - set all unused pins to DOUT - done
' - only send a temperature every 10 minutes and then put the MM and HC-12 to sleep in between - done
' - only send a temperature if it differs from the previous reading - done
' - HC-12s to power mode FU2 (necessitates 4,800 baud) - done using Rob Rozee's HC-12 Configuration program
' - Set the MM to a slow speed - reduced MM to 20 (any slower & TEMPR returns "1000" = error)
' - Don't need to ground unused pins - not grounded

Dim Integer Chksum
Dim Float Temp, TempOld
Dim String StationID = "3" 'Apply a unique No to each remote station (ID 1 = Base Station)
CPU 20 'Set the CPU's speed to the slowest that still enables a TEMPR reading

'Set all unused pins as DOUT
'Leave pins 1, 8, 11, 12, 13, 18, 21, 27 and 28 alone for now
SETPIN 2, DOUT
SETPIN 3, DOUT
SETPIN 4, DOUT
SETPIN 5, DOUT
SETPIN 6, DOUT
SETPIN 7, DOUT

SETPIN 9, DOUT
SETPIN 10, DOUT

SETPIN 14, DOUT 'Pin 14 used as the HTC-12 SET signal so is to be set as DOUT anyway
SETPIN 15, DOUT

'Pin 16 is used by the TempR command so leave for now
SETPIN 17, DOUT
SETPIN 18, DOUT

'Pins 21 & 22 are set by the Com#1 Open and Close commands so leave for now
SETPIN 23, DOUT
SETPIN 24, DOUT
SETPIN 25, DOUT
SETPIN 26, DOUT

Open "COM1:4800" As #1 'Com1 uses pins 21 and 22 for Tx and Rx respectively. 4,800 required for mode FU2.
TempOld = 0 'Gets checked each reading. Only sends a value if it differs.
PIN(14) = 1 'zzzProbably unnecessary??

Do 'The main loop - it never ends
'Print Time$ 'zzz only here for debug
SendTemp 'Read and send the temperature via the HC-12 to the base station

' put the HC-12 to sleep
PIN(14) = 0 'Set pin low to enter SETUP mode
Pause 50 'Wait at least 40m seconds
Print #1, "AT+SLEEP"

'GetResponse 'Check that it responds "OK+SLEEP" - used in debugging
'print Tmp$

PIN(14) = 1 'Return the 'SET' line high again to exit SETUP mode

' put the MM to sleep
Close #1
CPU SLEEP 559 'Here to set the CPU sleep time in seconds (600 = 10 minutes)

'After a sleep - the MM wakes up. Then wakeup Comms and HC-12
Open "COM1:4800" As #1

'To wake up a sleeping HC-12, you have to pulse the 'SET' line low again(50mS should do it),
'then return the line high again and WAIT 200mS for the module to reset itself.
PIN(14) = 0 ' pin is set low - this enters Command mode
Pause 50

'then return the line high again and WAIT 200mS for the module to reset itself
PIN(14) = 1 ' pin is high
Pause 200
' HC-12 should now be OK to receive/send data
Loop
End

Sub SendTemp
Local String Out$
Local Integer Z
Temp = TEMPR(16)
If Temp = TempOld then
Exit Sub
Else
TempOld = Temp
EndIf

Out$ = CRC$("$AGMTW,"+Str$(Temp)+"," + StationID) 'This is close to an NMEA 0183 "water temperture" sentence $??MTW... with the StationID exchanged for "C" (Celsius)
Print Time$, " ", Out$ 'zzz Delete from production code
Print #1,Out$ '
pause 250
Print #1,Out$ 'Send it a second time
Pause 250
End Sub 'SendTemp

FUNCTION CRC$(Txt$) 'AS String 'Returns the Txt$ passed to it with "*hh" added, where hh is the NMEA Hex checksum
Chksum = 0
FOR n = 2 TO LEN(Txt$) 'n=2 makes it skip the leading $
Chksum=Chksum XOR ASC(MID$(Txt$,n,1))
NEXT n
CRC$=Txt$+"*"+HEX$(Chksum,2)
END FUNCTION

'Sub GetResponse 'Only used when debugging to check response to "AT+SLEEP" = "OK+SLEEP"
' Local integer i
' Local string x$
' Tmp$ = ""
' Do
' X$ = Input$(1,#1)
' If X$ = Chr$(13) then
' Exit Sub
' End If
' Tmp$ = Tmp$ + X$
' Loop
'End Sub
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:44pm 11 Aug 2017
Copy link to clipboard 
Print this post

play around with putting the CPU20 command right before measuring the temperture and then going back to CPU 5 right after. You might find you need a tiny delay after a CPU change.

Take off all LEDs if there are any (HC12 etc. why do manufacturers make them so bright? even hi efficiency, drive them thru a higher resistor. I always end up touching them with a marker to tone them down.)

Also, it is extreme, but think of powering the external devices via FETs using some of your unused pins to control the power to the devices (you'll have to take the 1820 out of parasitic VCC mode). If you go to 3 AAs this will overcome the voltage drop in the FET but you'll need to do something about the power to the MX170 - perhaps split the supply rails by tapping between cells 2 & 3. It is the only way to make sure something is really off. You'll need to play and might need a delay just before use and beware some things don't like signals on their inputs with no VCC applied - it rarely breaks them but moving into an indeterminant state internally can make power-drain worse. BS170, 2N7000 both can do a couple of hundred mA through them (HC-12 can get to 160 in hi-power mode!) and have gate thresholds that would suit your application. Bound to be others so check through your junk box. If you want to avoid using pull-down resistors on their gates, make sure you set the control pins LO first thing in your prog but even then I would recommend them.Edited by CaptainBoing 2017-08-13
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 01:00am 12 Aug 2017
Copy link to clipboard 
Print this post

Cap'n, thanks. No LEDs that I can see but would it have been OK to just take them out?
I'll make the speed changes and I like the idea of a third AA battery as the HC-12 can go to 5V. I could put it either side of the 4K7 resistor and see whether it or the other two die first (although the two could keep the one up so it is not too precise).
Cheers,
Andrew
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 02:36am 12 Aug 2017
Copy link to clipboard 
Print this post

  Andrew_G said   No LEDs that I can see but would it have been OK to just take them out?


It should be, most indicators run them as below - it is very bad practice to run a signal through them - unless you are specifically trying to exploit the properties of the LED.

Consider this: without the LED, no current flows to ground so reduced power consumption


Edited by CaptainBoing 2017-08-13
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 09:55am 12 Aug 2017
Copy link to clipboard 
Print this post

  Andrew_G said   I have been distracted over the last two months but I am still trying to minimise consumption on my remote temperature-sensing MM. I believe I have included all of your suggestions in the code below (if not pl. let me know) but I still have a sleep current of 0.5mA - much better than before but is it the best I can achieve?.

Is the DS18B20 causing this?


Andrew,

Time to measure the current through each the several branches of your simple circuit to get to the bottom of where that .5 mA is going to! I would start by measuring the HC-12 and the MX170.

According to the relevant data sheet information, you're still high by a few hundred microamps. (8 bit processors will go several orders magnitude lower than the MX170 in sleep current.)

When using sleep mode, in general lowering the clock speed of the uP does not give any advantage in long term average current use, since the uP when awake takes longer to accomplish its tasks while in run mode. The sleep mode current is fixed -- not affected by the run speed.

Incidentally, the minimum voltage for the DS18B20 in parasitic mode is 3 volts, whereas in direct power mode it's 2 volts. I'd recommend the direct power mode connection anyway.

HankEdited by HankR 2017-08-13
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 12:11pm 12 Aug 2017
Copy link to clipboard 
Print this post

Cap'n and Hank, thanks. You make some good points. I was wondering if consumption when asleep was affected by its awake speed. I now have some more things to try (it may be a day or so before I can report back). Andrew
 
Boppa
Guru

Joined: 08/11/2016
Location: Australia
Posts: 814
Posted: 08:30am 13 Aug 2017
Copy link to clipboard 
Print this post

  TassyJim said   compared with 80uA in FU2 mode


Seriously- someone actually named it the FU2 mode???

 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 10:24am 13 Aug 2017
Copy link to clipboard 
Print this post



I always felt the same with a "FAR CALL" (jumping to a shared address space in a paged block, switching in the block first).Edited by CaptainBoing 2017-08-14
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 02:13am 17 Aug 2017
Copy link to clipboard 
Print this post

  Andrew_G said   Do you have any experience of how long a MM should go with 2x AAs without the extra drain of the HC-12 (and DS1820)?


Just as a really rough estimate, 2500 mAh at 40 microamps (the latest typical sleep current from Microchip datasheets) works out to about 7 years. With durations that long, the self discharge needs to be accounted for. I would say that this is in the ballpark of the typical shelf life of an AA alkaline.

If you can get down to something like 100 to 150 microamps total average that should achieve a very practical battery life using AA alkalines.

That kind of total drain should be attainable if the HC-12 behaves in sleep as its datasheet claims.

 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 06:34pm 18 Aug 2017
Copy link to clipboard 
Print this post

Hi Hank, thanks for the encouragement. I'd be happy with that!
I've powered the DS18B directly and now have a test going to see how long the batteries will last. I'm also fiddling with the base station to make proper use of the data.
I'll report back from time to time.
I'm also thinking of reporting the temp every 15/20 or 30 minutes rather than the present 10 (and sleeping in between) and using a light dependent resistor to alter the reporting overnight. I'll get there . . .

Thanks to you all, Andrew.
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 06:04pm 19 Aug 2017
Copy link to clipboard 
Print this post

Golly, both lower idle mode currents are achieved by using the full 16mA current duty-cycled!

I discovered this trying to get a good measurement of the sleep current. So far the
sleep current doesn't seem to be much different than the lowest 80 uA idle current that is provided in FU2 mode.

This scope image shows the FU1, 3.6 mA average mode. The vertical scale is labelled in milliamps. The trace fuzz is due to noise pickup, not anything from the device under test.



 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025