Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Water Level meter - How to sleep mode Post ReplyPost New Topic
<< Prev Page of 3
Author
Message << Prev Topic | Next Topic >>
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 21 November 2018 at 1:06pm | IP Logged Quote Timbergetter

This project is progressing nicely thanks to the help I’ve received on this forum. I do have one problem though that is currently blocking further progress with the ATMEGA328P.

By disabling the Analog to Digital converter and the Brown Out Detection and then putting the 328P in to its Power-down mode, I am able to achieve a supply current of 5.8 microAmps. I can then reliably wake up the 328P using the on-chip Watch Dog Timer. The problem arises when I add the statement – SoftwareSerial myserial (2,3) – to my sketch code. The program runs as before, but when it enters the Sleep (Power-down) mode the 328P is now drawing about 750 microAmps rather than the 5.8 microAmps previously.

I would have thought that putting the 328P in to Sleep mode would have switched off any overhead needed to support SoftwareSerial. I suppose I could delete the SoftwareSerial instance before going to Sleep mode, but I don’t know how to do that. Any thoughts on what might be happening here?



Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
ryanm
Regular Member
Regular Member


Joined: 25 September 2015
Location: Australia
Online Status: Offline
Posts: 90
Posted: 21 November 2018 at 1:23pm | IP Logged Quote ryanm

Any reason you can't just use the hardware serial?
Back to Top View ryanm's Profile Search for other posts by ryanm
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 21 November 2018 at 2:11pm | IP Logged Quote Timbergetter

I am using the HC-12 wireless module in this project so I thought that SoftwareSerial was the appropriate interface.
Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
ryanm
Regular Member
Regular Member


Joined: 25 September 2015
Location: Australia
Online Status: Offline
Posts: 90
Posted: 21 November 2018 at 2:26pm | IP Logged Quote ryanm

Is your sensor serial interface as well?
Back to Top View ryanm's Profile Search for other posts by ryanm
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 21 November 2018 at 3:25pm | IP Logged Quote Timbergetter

The sensor is the JSN-SR04 ultrasonic with trigger and echo signals. I am also using pins 2 and 3 on the 328P for serial interface to upload programs.

I guess I come back to my question on why entering sleep mode does not switch off whatever resources the SoftwareSerial instance is consuming?
Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
JohnS
Guru
Guru


Joined: 18 November 2011
Location: United Kingdom
Online Status: Offline
Posts: 1725
Posted: 21 November 2018 at 5:54pm | IP Logged Quote JohnS

Just for a test, could you change to hardware serial and see if that fixes it?

Otherwise you probably need to hunt around the software to figure what's happening.

John
Back to Top View JohnS's Profile Search for other posts by JohnS
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 23 November 2018 at 2:04pm | IP Logged Quote Timbergetter






I thought I had ironed out the sleep mode issues while the project was in breadboard stage but as you can see the hardware has progressed a bit beyond that now.

The thing is functioning as intended, that is:
Wakes from sleep mode using on-chip WatchDog timer.
Grogster MosFet is awakened which in turn switches on HC12 and Ultrasonics.
Water level reading made and sent over the HC12.
Shut down MosFet.
Return to sleep mode.
So far so good.

The problem is that the sleep mode current of the entire device jumps from 6 µA to several hundred µA as soon as the SoftwareSerial instance is created.

If the “SoftwareSerial mySerial (3, 4)” statement is added to the sketch the sleep current jumps to around 106 µA. Initially I had erroneously reversed the pin assignment in that statement and this caused the sleep current to jump to 760 µA, (and of course the device did not function then). If I entirely remove the HC12 from the main board the sleep current drops back to 6 µA (with the SoftwareSerial statement present).

I would have thought that after entering sleep mode that the presence of a switched-off HC12 on any 328P pins should not have any significant effect on the current while in that sleep mode.

I note that the Digital Pin 3 that I am using for RX can also be used as one of the two interrupts (INT1) on the 328P, but I am not initialising this pin as an interrupt. I am initialising INT0 which is pin 2. Could the split personality of Pin 3 be accounting for what I am seeing? I would have to rebuild the breadboard to put this to the test.

Is there a way I can destruct the SoftwareSerial instance prior to going in to sleep mode? Could that work?
Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
ryanm
Regular Member
Regular Member


Joined: 25 September 2015
Location: Australia
Online Status: Offline
Posts: 90
Posted: 23 November 2018 at 2:31pm | IP Logged Quote ryanm

Sounds like one of the software serial pins is being left high or floating and it's letting current leak into the radio. Try sending the software serial lines low with a digital write before entering sleep mode.
Back to Top View ryanm's Profile Search for other posts by ryanm
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 23 November 2018 at 2:58pm | IP Logged Quote Timbergetter

Many thanks Ryanm. That worked absolutely. I am now back in the race for a battery powered water level meter.
Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 10 December 2018 at 1:58pm | IP Logged Quote Timbergetter

My water level sensor is working as intended when the supply voltage is above about 4.55 v. The ATmega328P wakes from sleep mode sends DP5 high thereby switching on the MosFet which in turn switches on the ultrasonic sensor and the HC12 radio. After transmitting the reading the MosFet is switched off by sending DP5 low and then the ATmega328P is put into sleep mode for roughly 8 seconds (for testing sessions).

When the supply voltage falls below 4.55 v the system works for 1 or 2 or even up to 6 sleep cycles, but then goes into a state where DP5 is stuck high and the MosFet is stuck on. The attached DSO trace is illustrating this situation for a supply voltage of 4.0 v. Channel 1 (yellow) cleanly goes high for 1 second and for two sleep cycles but on the third attempt becomes stuck high. Channel 2 (blue) shows the output of the MosFet which correspondingly goes on for 2 cycles but becomes stuck on after the third attempt.

I do not understand the behaviour of the MosFet output trace which seems to indicate an oscillating ramp up to about 3.5 v ahead of DP5 going high.

Any thoughts on what might be going on here would be most welcomed.



Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 
Timbergetter
Newbie
Newbie


Joined: 08 October 2018
Location: Australia
Online Status: Offline
Posts: 22
Posted: 12 December 2018 at 3:23pm | IP Logged Quote Timbergetter

I have done 2 things that seems to have improved things somewhat:

1. Made the pull-down resistor for ATmega328P’s output pin D5 more aggressive by changing value from 10k to 4.7k.
2. Reduced the R7 resistance going from pin D5 to the base of Q10 from 1000 ohms to 470 ohms. (refer to Grogster’s suggested circuit on upper part of Page 2 of this thread)

These two adjustments seem to allow the supply voltage to drop down to around 4.0 volts before the ATmega328P’s pin D5 hangs high. (It was 4.55 volts per my previous post). I was hoping to get it to continue operating down to around 3.7 volts to squeeze the best out of the 3 AA batteries, but at present the operation is unstable down there.

I am observing something on the DSO traces that I don’t understand but I suspect it might be a clue as to what’s going on. The Atmega pin D5 goes high for 1 second to carry out the waking duties. However for about 1.5 seconds prior to that pin going high there is a succession of spikes at intervals of 68 mSecs. These spikes seem to give rise to an increasing voltage for Vout (the output of the MosFet) which climbs to about 2.6 volts before switching on properly to about Vsupply. The traces below are for a Supply of 4.0 volts. When the Supply is up at 5 volts I get a similar ramping effect but not as pronounced. (it persistes for only 0.9 seconds rather than 1.5 seconds).

Does any of this make sense to anyone?



Back to Top View Timbergetter's Profile Search for other posts by Timbergetter
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
<< Prev Page of 3
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1094 seconds.
Privacy Policy     Process times : 0, 0.02, 0, 0.09