179 lines
18 KiB
HTML
179 lines
18 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.6"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Solar panel: measure.c Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtreedata.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">Solar panel
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.6 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('measure_8c_source.html',''); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="headertitle"><div class="title">measure.c</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="measure_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="preprocessor">#include <xc.h></span></div>
|
|
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span> </div>
|
|
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="preprocessor">#include "<a class="code" href="measure_8h.html">measure.h</a>"</span></div>
|
|
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="preprocessor">#include "<a class="code" href="mcc_8h.html">mcc_generated_files/mcc.h</a>"</span></div>
|
|
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span> </div>
|
|
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"><a class="line" href="measure_8c.html#a3ad11a109af35fa8de5e0b1b3e60142b"> 6</a></span><span class="preprocessor">#define VOLTAGE_CHANNEL 0x5</span></div>
|
|
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"><a class="line" href="measure_8c.html#a501e37e951966e98511c9c1eb0c7d397"> 7</a></span><span class="preprocessor">#define CURRENT_CHANNEL 0x6</span></div>
|
|
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"><a class="line" href="measure_8c.html#a00978ca9e8220475258dcbbbb7d29129"> 8</a></span><span class="preprocessor">#define ADC_RESOLUTION (1024 - 1)</span></div>
|
|
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"><a class="line" href="measure_8c.html#a0d196150332c5bf12bb9684b0f1cc975"> 9</a></span><span class="preprocessor">#define ADC_REFH 3300</span></div>
|
|
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"><a class="line" href="measure_8c.html#a8c8f27b35dfa40ccf31c1ee31479a31c"> 10</a></span><span class="preprocessor">#define GAIN 66</span></div>
|
|
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"><a class="line" href="measure_8c.html#a061cddbb720e9fd818a11a141e890f47"> 11</a></span><span class="preprocessor">#define RESISTOR 3</span></div>
|
|
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> </div>
|
|
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="comment">// Number of samples to do the averaging during measures</span></div>
|
|
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"><a class="line" href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae"> 14</a></span><span class="preprocessor">#define AVERAGE_SAMPLES 8</span></div>
|
|
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
|
|
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"><a class="line" href="measure_8c.html#a2b815e6730e8723a6d1d06d9ef8f31c0"> 16</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="measure_8c.html#a2b815e6730e8723a6d1d06d9ef8f31c0">adc_init</a>(<span class="keywordtype">void</span>)</div>
|
|
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span>{</div>
|
|
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span> <span class="comment">// TODO -> complete adc initialisation</span></div>
|
|
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span> <span class="comment">//offsetCurrent = measure_current(0);</span></div>
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> </div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span>}</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> </div>
|
|
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="keyword">static</span> uint16_t measure_adc(uint8_t channel)</div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span>{</div>
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <span class="keywordflow">return</span> (uint16_t) (<a class="code hl_function" href="adc_8c.html#a81501f9b96aa9bb8dbe63b49d0f8e909">ADC_GetConversion</a>(channel));</div>
|
|
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span>}</div>
|
|
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> </div>
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> </div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> </div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"><a class="line" href="measure_8c.html#a104c0f284978c4cc8d34d36677a97e72"> 37</a></span>uint16_t <a class="code hl_function" href="measure_8c.html#a104c0f284978c4cc8d34d36677a97e72">measure_voltage</a>()</div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span>{</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> uint32_t sum = 0;</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> </div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae">AVERAGE_SAMPLES</a>; i++) {</div>
|
|
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> sum += measure_adc(<a class="code hl_define" href="measure_8c.html#a3ad11a109af35fa8de5e0b1b3e60142b">VOLTAGE_CHANNEL</a>);</div>
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> }</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> sum /= <a class="code hl_define" href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae">AVERAGE_SAMPLES</a>;</div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> sum = (sum * <a class="code hl_define" href="measure_8c.html#a0d196150332c5bf12bb9684b0f1cc975">ADC_REFH</a>) / <a class="code hl_define" href="measure_8c.html#a00978ca9e8220475258dcbbbb7d29129">ADC_RESOLUTION</a>;</div>
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> <span class="keywordflow">return</span> (uint16_t)(sum);</div>
|
|
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span>}</div>
|
|
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> </div>
|
|
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"><a class="line" href="measure_8c.html#ad77a3b79bc20b11c0d5462cc0b7134b3"> 49</a></span>uint16_t <a class="code hl_function" href="measure_8c.html#ad77a3b79bc20b11c0d5462cc0b7134b3">measure_current</a>(uint16_t offset)</div>
|
|
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span>{</div>
|
|
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> uint32_t sum = 0;</div>
|
|
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i< <a class="code hl_define" href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae">AVERAGE_SAMPLES</a>; i++){</div>
|
|
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> sum += measure_adc(<a class="code hl_define" href="measure_8c.html#a501e37e951966e98511c9c1eb0c7d397">CURRENT_CHANNEL</a>);</div>
|
|
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> } </div>
|
|
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> uint32_t m = (sum / <a class="code hl_define" href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae">AVERAGE_SAMPLES</a>); <span class="comment">// m is bits</span></div>
|
|
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> m = (m * <a class="code hl_define" href="measure_8c.html#a0d196150332c5bf12bb9684b0f1cc975">ADC_REFH</a>) / <a class="code hl_define" href="measure_8c.html#a00978ca9e8220475258dcbbbb7d29129">ADC_RESOLUTION</a>; <span class="comment">// m is mV</span></div>
|
|
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> m *= 1000; <span class="comment">// m is uV</span></div>
|
|
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> m /= <a class="code hl_define" href="measure_8c.html#a8c8f27b35dfa40ccf31c1ee31479a31c">GAIN</a>;</div>
|
|
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> m /= <a class="code hl_define" href="measure_8c.html#a061cddbb720e9fd818a11a141e890f47">RESISTOR</a>; <span class="comment">// m is uA</span></div>
|
|
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keywordflow">if</span>(m <= offset){</div>
|
|
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> m = 0;</div>
|
|
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> m -= offset;</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> }</div>
|
|
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> </div>
|
|
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordflow">return</span> (uint16_t)m;</div>
|
|
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span>}</div>
|
|
<div class="ttc" id="aadc_8c_html_a81501f9b96aa9bb8dbe63b49d0f8e909"><div class="ttname"><a href="adc_8c.html#a81501f9b96aa9bb8dbe63b49d0f8e909">ADC_GetConversion</a></div><div class="ttdeci">adc_result_t ADC_GetConversion(adc_channel_t channel)</div><div class="ttdef"><b>Definition:</b> <a href="adc_8c_source.html#l00109">adc.c:109</a></div></div>
|
|
<div class="ttc" id="amcc_8h_html"><div class="ttname"><a href="mcc_8h.html">mcc.h</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a00978ca9e8220475258dcbbbb7d29129"><div class="ttname"><a href="measure_8c.html#a00978ca9e8220475258dcbbbb7d29129">ADC_RESOLUTION</a></div><div class="ttdeci">#define ADC_RESOLUTION</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00008">measure.c:8</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a061cddbb720e9fd818a11a141e890f47"><div class="ttname"><a href="measure_8c.html#a061cddbb720e9fd818a11a141e890f47">RESISTOR</a></div><div class="ttdeci">#define RESISTOR</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00011">measure.c:11</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a0772f4f0c5e19d53263d12a0c0b296ae"><div class="ttname"><a href="measure_8c.html#a0772f4f0c5e19d53263d12a0c0b296ae">AVERAGE_SAMPLES</a></div><div class="ttdeci">#define AVERAGE_SAMPLES</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00014">measure.c:14</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a0d196150332c5bf12bb9684b0f1cc975"><div class="ttname"><a href="measure_8c.html#a0d196150332c5bf12bb9684b0f1cc975">ADC_REFH</a></div><div class="ttdeci">#define ADC_REFH</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00009">measure.c:9</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a104c0f284978c4cc8d34d36677a97e72"><div class="ttname"><a href="measure_8c.html#a104c0f284978c4cc8d34d36677a97e72">measure_voltage</a></div><div class="ttdeci">uint16_t measure_voltage()</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00037">measure.c:37</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a2b815e6730e8723a6d1d06d9ef8f31c0"><div class="ttname"><a href="measure_8c.html#a2b815e6730e8723a6d1d06d9ef8f31c0">adc_init</a></div><div class="ttdeci">void adc_init(void)</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00016">measure.c:16</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a3ad11a109af35fa8de5e0b1b3e60142b"><div class="ttname"><a href="measure_8c.html#a3ad11a109af35fa8de5e0b1b3e60142b">VOLTAGE_CHANNEL</a></div><div class="ttdeci">#define VOLTAGE_CHANNEL</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00006">measure.c:6</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a501e37e951966e98511c9c1eb0c7d397"><div class="ttname"><a href="measure_8c.html#a501e37e951966e98511c9c1eb0c7d397">CURRENT_CHANNEL</a></div><div class="ttdeci">#define CURRENT_CHANNEL</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00007">measure.c:7</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_a8c8f27b35dfa40ccf31c1ee31479a31c"><div class="ttname"><a href="measure_8c.html#a8c8f27b35dfa40ccf31c1ee31479a31c">GAIN</a></div><div class="ttdeci">#define GAIN</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00010">measure.c:10</a></div></div>
|
|
<div class="ttc" id="ameasure_8c_html_ad77a3b79bc20b11c0d5462cc0b7134b3"><div class="ttname"><a href="measure_8c.html#ad77a3b79bc20b11c0d5462cc0b7134b3">measure_current</a></div><div class="ttdeci">uint16_t measure_current(uint16_t offset)</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00049">measure.c:49</a></div></div>
|
|
<div class="ttc" id="ameasure_8h_html"><div class="ttname"><a href="measure_8h.html">measure.h</a></div><div class="ttdoc">Measuring current and voltage from the solar panel.</div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="measure_8c.html">measure.c</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|