Roboard RB-100 A/D Channel 的應用...

紅外線測距 Sharp GP2Y0A02 成功嚕~

從 I2C 拉出 +5V
然後接上..
A/D Pin 1 (信號)
A/D Pin 2 (接地)
換算電壓 -> 距離, 程式碼如下:

spi_Initialize(SPICLK_21400KHZ );
float volts;
float cm=0;
int channel = 0;
float VOLTS_PER_UNIT = 0.0049F;        // (.0049 for 10 bit A-D)
int val = ad7918_ReadChannel ( channel, //channel = 0 ~ 7
                        AD7918MODE_RANGE_2VREF, AD7918MODE_CODING_1023);
volts = (float)val * VOLTS_PER_UNIT;
cm = 60.495 * pow ( (float)volts, (float)-1.1904);

沒有留言:

張貼留言