AnsweredAssumed Answered

TWR k60 adc with MQX driver

Question asked by DALE RODDA on Aug 8, 2012
Latest reply on Oct 26, 2012 by David E Seymour

I am using a K60512N demo board and I am working on replacing the ADC_task with a task that uses the MQX driver. I want to have read two channels 10 times using light weight events to control the reads. The following code reads the channel on then never runs again.

 

I thought  the continuously running ADC would keep trippering events that would trigger the reads.

 

 


#define CHANNEL_1_EVENT_MASK (0x01)
#define CHANNEL_2_EVENT_MASK (0x02)

/* ADC device init struct */
const ADC_INIT_STRUCT adc_init = {
   ADC_RESOLUTION_DEFAULT,     /* resolution */
};

static LWEVENT_STRUCT evn;

/* Logical channel #1 init struct */
const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 =
{
   ADC1_SOURCE_ADPM1, /* physical ADC channel */
   ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_NOW, /* runs continuously after IOCTL trigger */
   10,             /* number of samples in one run sequence */
   0,              /* time offset from trigger point in us */
   100000,         /* period in us (= 0.1 sec) */
   0x10000,        /* scale range of result (not used now) */
   10,             /* circular buffer size (sample count) */
   MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
   &evn,
   CHANNEL_1_EVENT_MASK            /* mask of event to be set */
};

/* Logical channel #2 init struct */
const ADC_INIT_CHANNEL_STRUCT adc_channel_param2 =
{
   ADC1_SOURCE_AD3,
   ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_NOW, /* runs continuously after IOCTL trigger */
   10,             /* number of samples in one run sequence */
   0,              /* time offset from trigger point in us */
   100000,         /* period in us (= 0.1 sec) */
   0x10000,        /* scale range of result (not used now) */
   10,             /* circular buffer size (sample count) */
   MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
   &evn,
   CHANNEL_2_EVENT_MASK            /* mask of event to be set */
};


void adcTask(uint_32 dummy) {
   ADC_RESULT_STRUCT dataCh1, dataCh2;
   _mqx_int i;
   MQX_FILE_PTR f, f_ch1, f_ch2;

   if( _lwevent_create(&evn, LWEVENT_AUTO_CLEAR) != MQX_OK ) {
      _NextGenErrorExit( ADC_CREATE_EVENT_ERROR );
   }


   f = fopen(MY_ADC, (const char*)&adc_init);
   if( f == NULL ) {
      _NextGenErrorExit( ADC_FOPEN_DEVICE_ERROR );
   }

   f_ch1 = fopen(MY_ADC "first", (const char*)&adc_channel_param1);
   if( f_ch1 == NULL ) {
      _NextGenErrorExit( ADC_FOPEN_CHANNEL_1_ERROR );
   }

   f_ch2 = fopen(MY_ADC "second", (const char*)&adc_channel_param2);
   if( f_ch2 == NULL ) {
      _NextGenErrorExit( ADC_FOPEN_CHANNEL_2_ERROR );
   }

   ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);

   while( 1 ) {
      if( _lwevent_wait_ticks(&evn, CHANNEL_1_EVENT_MASK & CHANNEL_1_EVENT_MASK, TRUE, 0) == MQX_OK ) {
         read(f_ch1, &dataCh1, sizeof(dataCh1) );
         read(f_ch2, &dataCh2, sizeof(dataCh2) );
      } else {
         _NextGenErrorExit( ADC_WAIT_FOR_EVENT_ERROR );
      }
   }

 

 

Outcomes