<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">ADXL 은 3g 가속도 센서이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">3g 는 3-axis 라는 얘기는 아니다....... 쓸데없는 얘기군......</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">가속도 센서의 1g 는 중력 가속도인 9.8m/s<span style="font-size: 11pt;">²&nbsp;</span>이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">그래서 나는 ADC 에서 나오는 값을 받아서 이&nbsp;9.8m/s<span style="font-size: 11pt;">²&nbsp;<span style="font-size: 9pt;">을 이용했다.</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;"><br /></span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;">일단 ADC 에서 나오는 값을 대략 10개를 받아서 10으로 나눈다.</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;">소스상으론 11 로 나눠야지 값이 잘 나오는 듯 하다.</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;"><br /></span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;">물론 이 값들은 전압값으로 환산을 한다.</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;">현재 MCP3208 이용 아날로그 값을 받아오므로</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;"><br /></span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">accel_X = read_mcp3208*Vref/4095&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">로 하면 되겠다. Vref 는 기준전압. 4095 는 mcp3208 이 12bit 이므로 4095의 분해능을 갖는다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이상의 공식으로 전압값을 산출 한다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">그리고 ADXL335 의 데이터 시트를 보면 공급전압 Vs = 3.6V 일 때 sensitivity는 0.36V 로 되어있다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이를 내가 공급한 공급전압에 맞춰 비례식에 넣으면</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">3.6V : 0.36V = 3.3V : x</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이렇게 하면 x = 0.33V 가 나오게 된다. 즉 현재 나의 기준에서 sensitivity 는 0.33V 인 것이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이제 이 0.33V 를 이용해서 가속도 값을 산출 해 낸다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">accel_X = accel_X*9.8/0.33</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이 과정을 통하면 센서의 X 축을 땅으로 향하게 했을때 약 9.8XXX 의 값들이 나오게 된다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">내 생각엔 1g의 값이 나온다고 본다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이제 속도값을 구한다. 속도와 거리 모두 시간에 비례하거나 반비례한다. 즉 시간 이용해야 정확한 값을 구해 낼 수 있는 것이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">속도 = 거리/시간</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">거리 = 속도 * 시간</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이것은 어렸을 때 배운다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">물론 ADC 의 sampling rate 를 이용해서 값을 구해 내는 것이 더 정확할 수 있을것이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">하지만 일단 1초 단위로 끊어서 계산을 해 보겠다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">1초로 계산을 하려면 timing/count 를 써야한다.&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">알아서 쓰길 바랍니다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">속도와 가속도의 관계는 가속도가 일정하거나 (+) 방향으로 증가할때 속도는 증가하고</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">가속도가 (-)방향으로 증가한다면 감소하게 된다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">그리고 가속도가 0 이라면 속도는 등속도가 된다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="background-color: #ffef00;">그리고 가장 중요한 가속도를 적분하면 속도이고, 속도를 적분하면 거리이다.</span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">그렇다면 가속도가&nbsp;&nbsp;9.8m/s<span style="font-size: 11pt;">²&nbsp;<span style="font-size: 9pt;">﻿이라면 3초후의 속도는 얼마일까?</span></span></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">만약 가속도가 일정하게&nbsp;9.8m/s<span style="font-size: 11pt;">²<span style="font-size: 9pt;">﻿</span></span>&nbsp;3초 후의 속도는 9.8*3 m/s 가 될 것이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">즉 29.4m/s 가 되는 것이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">이제 거리계산이다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">거리는 매 1초 마다의 속도값을 더하면 된다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">소스로는 아래와 같다.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; velocityx[1] = (acceleration_x[0] + ((acceleration_x[2] - acceleration_x[0])/2))*vel_count[1]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //속도 구간 계산.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">velocityy[1] = acceleration_y[0] + ((acceleration_y[2] - acceleration_y[0])/2);</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">velocityz[1] = acceleration_z[0] + ((acceleration_z[2] - acceleration_z[0])/2);</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;diff_distance_x = velocityx[0]+((velocityx[1] - velocityx[0])/2);</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;diff_distance_y = velocityy[0]+((velocityy[1] - velocityy[0])/2);</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;diff_distance_z = velocityz[0]+((velocityz[1] - velocityz[0])/2);</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((diff_distance_x &gt; -0.001) &amp;&amp; (diff_distance_x &lt;0.001))diff_distance_x=0;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((diff_distance_y &gt; -0.001) &amp;&amp; (diff_distance_y &lt;0.001))diff_distance_y=0;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((diff_distance_z &gt; -0.001) &amp;&amp; (diff_distance_z &lt;0.001))diff_distance_z=0;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(vel_count[1] - vel_count[0] != 0)</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;distance_x[1] = distance_x[0] + diff_distance_x; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //거리 계산.</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;distance_y[1] = distance_y[0] + diff_distance_y; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;distance_z[1] = distance_z[0] + diff_distance_z; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;</p>
<p style="padding: 0px; line-height: 1.5; color: #8a837e; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 11pt;"><span style="font-size: 9pt;">틀릴 수도 있다. 점차 보완 해 나갈 것이다.</span></span></p>
<p>
   <p>&nbsp;</p>
   </p>
<div class="autosourcing-stub-extra" style="line-height: 1.5; zoom: 1; opacity: 1;">
   <p style="margin: 11px 0px 7px; padding: 0px; line-height: 1.5; font-size: 12px; font-family: Dotum; font-style: normal; font-weight: normal;"><strong style="padding: 0px 7px 0px 0px;">[출처]</strong><span>&nbsp;</span><a href="http://blog.naver.com/kwsiye/120169673988" target="_blank" style="text-decoration: none;">가속도 센서 ADXL335 거리값 구하기.</a><span style="padding: 0px 7px 0px 5px;">|</span><strong style="padding: 0px 7px 0px 0px;">작성자</strong><span>&nbsp;</span><a href="http://blog.naver.com/kwsiye" target="_blank" style="text-decoration: none;">해비치cafe</a></p>
   </div>