static void __idg300_init(SENSOR* sensor){ IDG300* device = (IDG300*)sensor; // The default is that device should be outputing 1.5v ie ADC10 = 307 device->x_zero = 0; device->y_zero = 0; // Read 8 times for(uint8_t i=0; i<8; i++){ device->x_zero += a2dReadMv(device->x_pin); device->y_zero += a2dReadMv(device->y_pin); } // Get average device->x_zero /= 8; device->y_zero /= 8; }
static GYRO_TYPE __read_channel(ADC_CHANNEL pin, uint16_t zero){ int16_t adc = a2dReadMv(pin); adc -= zero; // Divide by 2mV per degree GYRO_TYPE rtn = adc / 2; return rtn; }
// Read all the values and store into the device static void __GP2Y0A710K0F_read(SENSOR* sensor){ Sharp_GP2Y0A710K0F* device = (Sharp_GP2Y0A710K0F*)sensor; // uint16_t adc = a2dConvert10bit(device->adcPin); // device->distance.cm = 500000000.0 * pow(adc,-2.4723); uint16_t adc = a2dReadMv(device->adcPin); device->distance.cm = 25270743335.99 * pow(adc,-2.4723); }
static void init(SENSOR* sensor){ // The default is that device should be outputing 1.23v ie ADC10 of 251 LPRY530AL* device = (LPRY530AL*)sensor; device->x_zero = 0; device->y_zero = 0; device->z_zero = 0; // Read 8 times for(uint8_t i=0; i<8; i++){ device->x_zero += a2dReadMv(device->x_pin); device->y_zero += a2dReadMv(device->y_pin); device->z_zero += a2dReadMv(device->z_pin); } // Get average device->x_zero /= 8; device->y_zero /= 8; device->z_zero /= 8; }
static GYRO_TYPE __read_channel(ADC_CHANNEL pin, boolean slow, uint16_t zero){ int16_t adc = a2dReadMv(pin); adc -= zero; GYRO_TYPE rtn; if(slow){ rtn = fraction32(adc, ly530alh_slow_frac); }else{ rtn = fraction32(adc, ly530alh_fast_frac); } return rtn; }
static void __ly530alh_init(SENSOR* sensor){ LY530ALH* device = (LY530ALH*)sensor; // The default is that device should be outputing 1.23v ie ADC10 of 251 device->z_zero = 0; // Read 8 times for(uint8_t i=0; i<8; i++){ device->z_zero += a2dReadMv(device->z_pin); } // Get average device->z_zero /= 8; }
static GYRO_TYPE __read_channel(ADC_CHANNEL pin, boolean slow, uint16_t zero){ // Read the voltage im mV int16_t adc = 0; for(uint8_t s=0; s<SAMPLES;s++){ adc += a2dReadMv(pin); } adc /= SAMPLES; // Make zero relative adc -= zero; GYRO_TYPE rtn; if(slow){ // Divide by 3.33mV = multiply by 0.3 rtn = fraction32(adc, slow_frac); }else{ // Divide by 0.83mV = multiply by 1.2 rtn = fraction32(adc, fast_frac); } return rtn; }