// perform conversion, check for changes, and post events void adc_poll(void) { #if 1 #else static u16 adcVal[4] = {0, 0, 0, 0}; static event_t e; u8 i; adc_convert(&adcVal); #if 0 for(i=0; i<4; i++) { // TODO: /// probably want more filtering before posting events?? i dunno // if(adcVal[i] != adcOldVal[i]) { /// this is a dirty way! but the two lower bits are pretty noisy. valMask = adcVal[i] & 0xff8; if( valMask != adcOldVal[i] ) { adcOldVal[i] = valMask; e.type = adctypes[i]; // use the data without the mask e.data = (S16)(adcVal[i]); event_post(&e); } } #else /// test with no filtering.. maybe this is fine for(i=0; i<4; i++) { e.type = adctypes[i]; e.data = (S16)(adcVal[i]); event_post(&e); } #endif #endif }
void read_distance_left(sensor_data_t* sensor_data) { /* Select left distance sensor input. */ ADMUX = 0x65; sensor_data->distance[0] = adc_convert(); }
void read_distance_right(sensor_data_t* sensor_data) { /* Select right distance sensor input. */ ADMUX = 0x64; sensor_data->distance[1] = adc_convert(); }
// handler for the ADC event static void handler_PollADC(s32 data) { u16 i; adc_convert(&adc); // CLOCK POT INPUT i = adc[0]; i = i>>2; if(i != clock_temp) { // 1000ms - 24ms clock_time = 25000 / (i + 25); timer_set(&clockTimer, clock_time); } clock_temp = i; // PARAM POT INPUT // value will be in the 0-4095 range, scale accordingly // also be aware there is quite a bit of noise on the input, so you might want to desensitize it a bit // by averaging several values or some other technique u8 newPotValue = adc[1]; if (newPotValue != prevPotValue) { prevPotValue = newPotValue; // value changed which means the param knob was turned, do whatever you need to do here // don't do anything too long - for long operations consider using timers } }
static void handler_PollADC(s32 data) { u8 i,n; adc_convert(&adc); for(i=0;i<3;i++) { if(ain[i].hys) { if(port_edit == 1) { if(i == 0) { aout[3].slew = port_time = ((adc[i] + adc_last[i])>>1 >> 4); // print_dbg("\r\nportamento: "); // print_dbg_ulong(port_time); } } else if(all_edit) { if(mode == mNormal) { for(n=0;n<8;n++) es.cv[n][i] = aout[i].target = (adc[i] + adc_last[i])>>1; aout[i].step = 5; // smooth out the input } else if(mode == mSlew) { for(n=0;n<8;n++) es.slew[n][i] = aout[i].slew = (adc[i] + adc_last[i])>>1; } }
static void handler_MonomeConnect(s32 data) { // print_dbg("\r\n// monome connect /////////////////"); key_count = 0; SIZE = monome_size_x(); LENGTH = SIZE - 1; // print_dbg("\r monome size: "); // print_dbg_ulong(SIZE); VARI = monome_is_vari(); // print_dbg("\r monome vari: "); // print_dbg_ulong(VARI); if(VARI) re = &refresh; else re = &refresh_mono; shape_key_count = 0; key_count = 0; timers_set_monome(); monome_set_quadrant_flag(0); monome_set_quadrant_flag(1); // turn on ADC polling, reset hysteresis adc_convert(&adc); reset_hys(); timer_add(&adcTimer,61,&adcTimer_callback, NULL); }
int main( void ) { uint8_t already_converted = 0; /* initialize Robostix 1 */ controller_init( ); while( 1 ) { /* check if communication is upright */ if( flag_check_delay ) { check_receive_delay( ); } /* check if new serial or parallel data available */ if( serial_is_new_data( ) )//|| parallel_is_new_data( ) ) { process_data_packet( ); } /* check if new IMU data available */ if( dm3gx1_is_new_data( ) && !dm3gx1_get_data( &javiator_data ) ) { javiator_data.state |= ST_NEW_DATA_IMU; } /* check if new analog sonar data available */ if( minia_is_new_data( ) && !already_converted ) { /* convert sonar data */ adc_convert( ADC_CH_SONAR ); already_converted = 1; } else if( !minia_is_new_data( ) ) { already_converted = 0; } /* check if new converted sonar data available */ if( adc_is_new_data( ADC_CH_SONAR ) && !adc_get_data( ADC_CH_SONAR, &javiator_data.sonar ) ) { javiator_data.state |= ST_NEW_DATA_SONAR; } /* check if new converted battery data available */ if( adc_is_new_data( ADC_CH_BATT ) ) { adc_get_data( ADC_CH_BATT, &javiator_data.batt ); } } return( 0 ); }
void main(void) { lcd_init(); draw_adc_display(); while(1) { /* Another method for ADC_INT_DIS and ADC_INT_EN_SLEEP mode is shown below */ /* unsigned int adc_result=0; adc_init(ADC_INT_DIS, 200, 0); adc_result=adc_convert(0); */ /* After a adc_init() command using interrupt, at least one conversion will take place. */ /* If you use ADC_INT_DIS mode no conversion will be initiated */ #if ADC_NO_INT_MODE_NEEDED == 1 /* Dont use ADC interrupt */ adc_init(ADC_INT_DIS, 200, 0); adc_convert(0); #endif #if ADC_SLEEP_MODE_NEEDED == 1 /* Start conversion with sleep. for subsequent conversions use the adc_convert(x) function */ adc_init(ADC_INT_EN_SLEEP, 200, 1); adc_convert(2); #endif #if ADC_INT_MODE_NEEDED == 1 /* Start auto conversions in channel 3 using interrupt */ adc_init(ADC_INT_EN, 200, 3); /* switch to channel 4. The switch will be done after one complete conversion at channel 3 */ /* the function will return after at least one conversion is perfomed at channel 4 */ adc_set_channel(4); #endif #if ADC_SCAN_MODE_NEEDED == 1 /* Scan channels 5,6,7 */ adc_init( ADC_INT_EN_SCAN, 200, (1<<ADC_CH5)|(1<<ADC_CH6)|(1<<ADC_CH7) ); #endif display_adc_readings(); } }
int analog_input_pin_read(struct analog_input_pin_t *self_p) { uint16_t sample; if (adc_convert(&self_p->adc, &sample, 1) == 0) { return (sample); } return (-1); }
void read_linesensor(sensor_data_t* sensor_data) { /* Select line sensor input. */ ADMUX = 0x67; uint8_t channel; for(channel = line_sensor_first; channel <= line_sensor_last; channel++){ PORTA = channel & 0x0F; sensor_data->line[channel] = adc_convert(); } }
static void handler_PollADC(s32 data) { u16 i; adc_convert(&adc); // CLOCK POT INPUT i = adc[0]; i = i>>2; if(i != clock_temp) { // 500ms - 12ms clock_time = 12500 / (i + 25); // print_dbg("\r\nclock (ms): "); // print_dbg_ulong(clock_time); timer_set(&clockTimer, clock_time); } clock_temp = i; }
void pm25_read() { asm("sim"); //禁止中断 LED_G = 0; int i = 7; u16 comp; u16 value; u16 pm25_value[6]={0,0,0,0,0,0}; char string_pm25[15]; #if 0 u16 temp_value[2]={0,0}; while(1) { temp_value[0] = read_pm25_byte(); temp_value[1] = read_pm25_byte(); if((0xff == temp_value[0])&&(0xaa == temp_value[1])) break; } #endif while(!((read_pm25_byte()==0xff)&&(read_pm25_byte()==0xaa)));//查找0xff与0xaa相连,作为起始; for(i = 5;i >= 0;--i) { pm25_value[5-i] = read_pm25_byte(); //delay_us(4000); } comp = pm25_value[0] + pm25_value[1] + pm25_value[2] + pm25_value[3]; if(comp >255) //处理数据溢出 comp -= 256; if(comp == pm25_value[4]) { LED_G = 1; } asm("rim"); //开总中断 //value = (pm25_value[0] << 8 | pm25_value[1]) * 5; //转化为mV; 0.2mg/m3对应1V value = (pm25_value[0] << 8 | pm25_value[1]); //直接转化为mg/m3 * 1000;0.2mg/m3对应1V adc_convert(string_pm25,value); Lcd_Write_Command( 0x01,1); //清屏 Lcd_Puts(0,1,"P25: mg/m3"); Lcd_Puts(4,1,(uchar*)string_pm25); }
int main() { int i, j; uint16_t samples[membersof(analog_pins)]; sys_start(); adc_module_init(); for (i = 0; i < membersof(adc); i++) { adc_init(&adc[i], analog_pins[i].adc_dev_p, analog_pins[i].pin_dev_p, ADC_REFERENCE_VCC, 1); } i = 0; while (1) { if ((i % 10) == 0) { print_header(); } std_printf(FSTR("|")); for (j = 0; j < membersof(adc); j++) { samples[j] = 0xffff; adc_convert(&adc[j], &samples[j], 1); } for (j = 0; j < membersof(adc); j++) { std_printf(FSTR(" %6d |"), (int)samples[j]); } std_printf(FSTR("\r\n")); thrd_sleep_ms(500); i++; } return (0); }
/* Sends the JAviator data to the Gumstix */ void send_javiator_data( void ) { uint8_t data[ JAVIATOR_LDAT_SIZE ]; ////////////////////////////////////////////////////////////////////////// javiator_data.id = motor_signals.id; ////////////////////////////////////////////////////////////////////////// /* encode JAviator data */ javiator_ldat_to_stream( &javiator_data, data, JAVIATOR_LDAT_SIZE ); /* transmit JAviator data */ serial_send_data( COMM_JAVIATOR_DATA, data, JAVIATOR_LDAT_SIZE ); ////////////////////////////////////////////////////////////////////////// javiator_data.state = 0; ////////////////////////////////////////////////////////////////////////// #if 0 /* increment motor signals ID before being sent on round trip */ ++motor_signals.id; /* encode motor signals ID and enable-sensors flag, which corresponds to the inverted shut-down flag */ data[0] = (uint8_t)( motor_signals.id >> 8 ); data[1] = (uint8_t)( motor_signals.id ); data[2] = (uint8_t)( !flag_shut_down ); /* request new sensor data */ parallel_send_data( COMM_SENSOR_DATA, data, 3 ); #endif /* request new IMU data */ dm3gx1_request( ); /* convert battery data */ adc_convert( ADC_CH_BATT ); }