Adc read

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adc read

760 Views
danielecortella
Contributor V

Hi, i'm trying to read a data from the ADC on a TWRMCF51MM256 but i have a problem with the function

adc_ch4 = fopen("adc:four", (const char*)&adc_channel_param4);//inizializzo il canale quattro dell'adc

that return a null, and where the parameter are

ADC_INIT_CHANNEL_STRUCT adc_channel_param4 = {

  ADC_SOURCE_AD4, /* physical ADC channel */

  ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_NOW, /* one sequence is sampled after fopen */

  1,             /* number of samples in one run sequence */

  0,         /* time offset from trigger point in us */

  600000,         /* period in us (= 0.6 sec) */

  0x10000,        /* scale range of result (not used now) */

  1,             /* circular buffer size (sample count) */

  MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */

  };

what i want to do is to read the data every second with this function

for(;;){

  printf("Triggering channel #4...");

  ioctl(adc_file, ADC_IOCTL_RUN_CHANNEL, NULL);

  if(read(adc_ch4, &data, sizeof(data)))

  printf("ADC ch 4: %4d ", data.result);

  _time_delay(1000);

  }

when is called the function ioctl the sistem stop to work, where is the error?

Sorry but I am at the beginning with this operating system

Thanks

Tags (2)
0 Kudos
3 Replies

358 Views
danielecortella
Contributor V

can you help me? Thanks

0 Kudos

358 Views
c0170
Senior Contributor III

Hello Daniele Cortellazzi,

any progress? Have you figured out why fopen returns null? What version of MQX do you use?

Regards,

0xc0170

0 Kudos

358 Views
danielecortella
Contributor V

Hi, in this days i'm working on other project. Seeing on the reference manual of mqx (i'm using mqx 3.8) i see that the struct is defined so:

const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 = {

ADC_SOURCE_AN1, /* physical ADC channel */

ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_NOW,

/* one sequence is sampled after fopen */

10, /* number of samples in one run sequence */

100000, /* time offset from trigger point in us */

500000, /* period in us (=500ms) */

0, /* reserved - not used */

10, /* circular buffer size (sample count) */

ADC_TRIGGER_2, /* logical trigger ID that starts this ADC channel */

&evn /* pointer to event */

0x01 /* event mask to be set */

}

and in my struct there isn't the &evn, is an error? i hope to test this this afternoon. Thanks

0 Kudos