Batmonitor » History » Version 14
Txinto Vaz, 11/13/2014 12:57 AM
1 | 1 | Txinto Vaz | h1. Construction of a BATmonitor |
---|---|---|---|
2 | 1 | Txinto Vaz | |
3 | 1 | Txinto Vaz | {{>toc}} |
4 | 1 | Txinto Vaz | |
5 | 1 | Txinto Vaz | Present mini-project will develop a Battery monitor using an Arduino Uno R3 and the uCANca tools. |
6 | 1 | Txinto Vaz | |
7 | 1 | Txinto Vaz | To build a testable circuit, we will implement a solution like this one: |
8 | 1 | Txinto Vaz | |
9 | 1 | Txinto Vaz | http://arduino.cc/en/Tutorial/ReadAnalogVoltage |
10 | 1 | Txinto Vaz | |
11 | 1 | Txinto Vaz | 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. |
12 | 1 | Txinto Vaz | |
13 | 1 | Txinto Vaz | h2. Project creation |
14 | 1 | Txinto Vaz | |
15 | 1 | Txinto Vaz | We will create a project called BatMonitor in uCANca. |
16 | 1 | Txinto Vaz | |
17 | 1 | Txinto Vaz | !Bat01.png! |
18 | 1 | Txinto Vaz | |
19 | 1 | Txinto Vaz | And add ourselves as team member (as contributor). |
20 | 1 | Txinto Vaz | |
21 | 1 | Txinto Vaz | !Bat02.png! |
22 | 1 | Txinto Vaz | |
23 | 5 | Txinto Vaz | h2. Functions specification |
24 | 5 | Txinto Vaz | |
25 | 1 | Txinto Vaz | Add the main function of the system: Monitor the battery voltage value. |
26 | 1 | Txinto Vaz | |
27 | 1 | Txinto Vaz | !Bat03.png! |
28 | 1 | Txinto Vaz | |
29 | 1 | Txinto Vaz | !Bat04.png! |
30 | 1 | Txinto Vaz | |
31 | 1 | Txinto Vaz | Add the secondary function of the system: Discretize battery voltage values into different battery ranges. |
32 | 1 | Txinto Vaz | |
33 | 1 | Txinto Vaz | !Bat05.png! |
34 | 1 | Txinto Vaz | |
35 | 1 | Txinto Vaz | Add a diagnostics function on battery: Warn (and register) battery low levels. |
36 | 2 | Txinto Vaz | |
37 | 2 | Txinto Vaz | !Bat06.png! |
38 | 3 | Txinto Vaz | |
39 | 3 | Txinto Vaz | And another diagnostic function for battery high: Warn (and register) battery high levels. |
40 | 3 | Txinto Vaz | |
41 | 3 | Txinto Vaz | !Bat07.png! |
42 | 3 | Txinto Vaz | |
43 | 3 | Txinto Vaz | As summary: |
44 | 3 | Txinto Vaz | |
45 | 3 | Txinto Vaz | !Bat08.png! |
46 | 4 | Txinto Vaz | |
47 | 4 | Txinto Vaz | To make the system more testable, we will introduce a function that uses the LED to inform of the current situation of the system: |
48 | 4 | Txinto Vaz | |
49 | 4 | Txinto Vaz | !Bat09.png! |
50 | 6 | Txinto Vaz | |
51 | 6 | Txinto Vaz | h2. Technical concept |
52 | 6 | Txinto Vaz | |
53 | 6 | Txinto Vaz | 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). |
54 | 6 | Txinto Vaz | |
55 | 6 | Txinto Vaz | We can use a tool like XCos or yEd to make and understandable diagram of the desired solution technical concept. |
56 | 7 | Txinto Vaz | |
57 | 7 | Txinto Vaz | In this case we will use XCos: |
58 | 7 | Txinto Vaz | |
59 | 7 | Txinto Vaz | !Bat10.png! |
60 | 8 | Txinto Vaz | |
61 | 8 | Txinto Vaz | !Bat11.png! |
62 | 9 | Txinto Vaz | |
63 | 10 | Txinto Vaz | warning. 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. |
64 | 10 | Txinto Vaz | |
65 | 9 | Txinto Vaz | warning. 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. |
66 | 11 | Txinto Vaz | |
67 | 11 | Txinto Vaz | h2. Using uCANca specification spreadsheet for 1D Discretizer |
68 | 11 | Txinto Vaz | |
69 | 11 | Txinto Vaz | We will use the document#11 spreadsheet for 1D Discretizer specification in order to specify the BAT ranges to be considered in our system. |
70 | 11 | Txinto Vaz | This document will automatically generate code and diagrams from the specification. |
71 | 11 | Txinto Vaz | |
72 | 11 | Txinto Vaz | 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). |
73 | 11 | Txinto Vaz | |
74 | 11 | Txinto Vaz | The file name will be renamed as: uCANca_BAT_1D_Discretizer_Spec_BAT.ods |
75 | 11 | Txinto Vaz | |
76 | 11 | Txinto Vaz | !Bat12.png! |
77 | 11 | Txinto Vaz | |
78 | 11 | Txinto Vaz | We will also rename the tabs and abbrevs inside the file to match this convention. |
79 | 11 | Txinto Vaz | |
80 | 11 | Txinto Vaz | !Bat13.png! !Bat14.png! !Bat15.png! |
81 | 12 | Txinto Vaz | |
82 | 12 | Txinto Vaz | 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. |
83 | 12 | Txinto Vaz | |
84 | 12 | Txinto Vaz | 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/ |
85 | 12 | Txinto Vaz | |
86 | 12 | Txinto Vaz | !http://www.groverfamily.org/wp-content/uploads/2013/06/volts-300x187.jpg! |
87 | 12 | Txinto Vaz | |
88 | 12 | Txinto Vaz | But the important thing to change is the "full scale" of our ADC (for Arduino is 5V): |
89 | 12 | Txinto Vaz | |
90 | 12 | Txinto Vaz | !Bat16.png! |
91 | 13 | Txinto Vaz | |
92 | 13 | Txinto Vaz | Then we will define correct BAT level frontiers for our application: |
93 | 13 | Txinto Vaz | |
94 | 13 | Txinto Vaz | !Bat17.png! |
95 | 13 | Txinto Vaz | |
96 | 13 | Txinto Vaz | And select the ranges to be displayed in the documentation: |
97 | 13 | Txinto Vaz | |
98 | 13 | Txinto Vaz | !Bat18.png! |
99 | 13 | Txinto Vaz | |
100 | 13 | Txinto Vaz | So we obtain documentation suitable for source code headers: |
101 | 13 | Txinto Vaz | |
102 | 13 | Txinto Vaz | <pre><code class="C"> |
103 | 13 | Txinto Vaz | /* -----_________________________________*/ |
104 | 13 | Txinto Vaz | /* -----| */ |
105 | 13 | Txinto Vaz | /* -----| HIGH */ |
106 | 13 | Txinto Vaz | /* -----| */ |
107 | 13 | Txinto Vaz | /* 15,5v| - - - - - - - - - - - - - - - */ |
108 | 13 | Txinto Vaz | /* -----| */ |
109 | 13 | Txinto Vaz | /* -----| NORMAL */ |
110 | 13 | Txinto Vaz | /* -----| */ |
111 | 13 | Txinto Vaz | /* 4,5v| - - - - - - - - - - - - - - - */ |
112 | 13 | Txinto Vaz | /* -----| */ |
113 | 13 | Txinto Vaz | /* -----| LOW */ |
114 | 13 | Txinto Vaz | /* -----| */ |
115 | 13 | Txinto Vaz | /* 0,0v|________________________________*/ |
116 | 13 | Txinto Vaz | |
117 | 13 | Txinto Vaz | </code></pre> |
118 | 13 | Txinto Vaz | |
119 | 13 | Txinto Vaz | And for WYSIWYG documentation: |
120 | 13 | Txinto Vaz | |
121 | 13 | Txinto Vaz | !Bat19.png! |
122 | 14 | Txinto Vaz | |
123 | 14 | Txinto Vaz | We will return later to this document in order to obtain automatically generated code directly from this specification in the implementation stage. |