Construction of a BATmonitor

Present mini-project will develop a Battery monitor using an Arduino Uno R3 and the uCANca tools.

To build a testable circuit, we will implement a solution like this one:

http://arduino.cc/en/Tutorial/ReadAnalogVoltage

After we have played with the potentiomenter, the idea is to switch the input to monitor the battery level of a robot or toy controlled by the Arduino.

Project creation

We will create a project called BatMonitor in uCANca.

And add ourselves as team member (as contributor).

Functions specification

Add the main function of the system: Monitor the battery voltage value.

Add the secondary function of the system: Discretize battery voltage values into different battery ranges.

Add a diagnostics function on battery: Warn (and register) battery low levels.

And another diagnostic function for battery high: Warn (and register) battery high levels.

As summary:

To make the system more testable, we will introduce a function that uses the LED to inform of the current situation of the system:

Technical concept

We will use an arduino uno R3 as microcontroller containing the software. We will have a module that reads the input from the ADC and infers the voltage value (as described in F1). Another module will select the current unfiltered battery level (as described in F2). Then a time filter will be applied to select stable values of battery levels (debouncing system for F2). No hysteresis, just time filtering. After that battery level is selected, a FSM algorithm will determine if the high/low battery level failure is present (after qualifying for a certain time in the specific low/high range), or has dissapeared (as described in F3 and F4). The FSM will also save the occurrence. And finally there must be another module that will control the blinking LED (according to F5).

We can use a tool like XCos or yEd to make and understandable diagram of the desired solution technical concept.

In this case we will use XCos:

Despite of the Scilab/XCos diagram, the counter is not limited to count between 0 to 2, in fact in our technical concept we have set maximum count of 255.
Due to Scilab/XCos error, the input names of the BATLevel2LED_Coder block are not correctly shown. By order(top to bottom): BatHigh_present, BatHigh_occurrences, BatLow_present, BatLow_occurrences.

Using uCANca specification spreadsheet for 1D Discretizer

We will use the Calc spreadsheets for specification spreadsheet for 1D Discretizer specification in order to specify the BAT ranges to be considered in our system.
This document will automatically generate code and diagrams from the specification.

We must sustitute XXX by the project name abbrev (just use BAT) and Sample by the name of the magnitude to be discretized (in this case, BAT again).

The file name will be renamed as: uCANca_BAT_1D_Discretizer_Spec_BAT.ods

We will also rename the tabs and abbrevs inside the file to match this convention.

As we don’t know by now the transfer function between the external battery and the voltage in the ADC, let’s keep the table values, they will be good for playing with the input potentiometer.

These values will finally depend on the hardware we use for sensing the battery. Typically it will be a voltage divider like the one described here (credits for the author of the article): http://www.groverfamily.org/solar-powered-basement/solar-panel-monitoring-system/

But the important thing to change is the “full scale” of our ADC (for Arduino is 5V):

Then we will define correct BAT level frontiers for our application:

And select the ranges to be displayed in the documentation:

So we obtain documentation suitable for source code headers:

 /*          -----_________________________________*/
 /*          -----|                                */
 /*          -----|          HIGH                  */
 /*          -----|                                */
 /*          15,5v| - - - - - - - - - - - - - - -  */
 /*          -----|                                */
 /*          -----|          NORMAL                */
 /*          -----|                                */
 /*           4,5v| - - - - - - - - - - - - - - -  */
 /*          -----|                                */
 /*          -----|          LOW                   */
 /*          -----|                                */
 /*           0,0v|________________________________*/

And for WYSIWYG documentation:

We will return later to this document in order to obtain automatically generated code directly from this specification in the implementation stage.

Bat01.png View (28.5 KB) Txinto Vaz, 11/12/2014 10:45 PM

Bat02.png View (13.6 KB) Txinto Vaz, 11/12/2014 10:46 PM

Bat03.png View (4.4 KB) Txinto Vaz, 11/12/2014 10:48 PM

Bat04.png View (20.5 KB) Txinto Vaz, 11/12/2014 10:57 PM

Bat05.png View (23.3 KB) Txinto Vaz, 11/12/2014 11:01 PM

Bat06.png View (23 KB) Txinto Vaz, 11/12/2014 11:02 PM

Bat08.png View (23.1 KB) Txinto Vaz, 11/12/2014 11:07 PM

Bat07.png View (26.6 KB) Txinto Vaz, 11/12/2014 11:07 PM

Bat09.png View (62.1 KB) Txinto Vaz, 11/12/2014 11:18 PM

Bat11.png View (68.7 KB) Txinto Vaz, 11/13/2014 12:16 AM

Bat10.png View (52.3 KB) Txinto Vaz, 11/13/2014 12:19 AM

Bat12.png View (20.7 KB) Txinto Vaz, 11/13/2014 12:35 AM

Bat13.png View (3.34 KB) Txinto Vaz, 11/13/2014 12:38 AM

Bat14.png View (10.7 KB) Txinto Vaz, 11/13/2014 12:38 AM

Bat15.png View (23.2 KB) Txinto Vaz, 11/13/2014 12:38 AM

Bat16.png View (8.47 KB) Txinto Vaz, 11/13/2014 12:45 AM

Bat17.png View (9.87 KB) Txinto Vaz, 11/13/2014 12:52 AM

Bat18.png View (10.3 KB) Txinto Vaz, 11/13/2014 12:52 AM

Bat19.png View (3.9 KB) Txinto Vaz, 11/13/2014 12:55 AM