AnsweredAssumed Answered

Operating more than 1 channel per ADC

Question asked by Myke Predko on Jun 21, 2013
Latest reply on Jul 1, 2013 by Myke Predko

Hi Folks,

 

In my application (developed in CW 10.4 and using MQX 4.0.1) I want to access more than one ADC on a channel (I will be using 7 between ADC0 and ADC1) in the K20 (using the TWRK20D72M as the development too while waiting for the PCBs). 

 

I am trying to to implement multiple channel reads for a single ADC in a single task and using them to trigger an lwevent.  I can do it successfully with a single channel per ADC in a task but not with multiple channels per ADC in a task. 

 

What I'm trying to do is:

  1. Create the lwevent for the ADC
  2. Open the ADC device
  3. Open a channel in the ADC that references the lwevent I created.  Opening the channel does not return an error and the task works with the different triggers as step 5 with the results listed below:
    1. "ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer)ADC_PDB_TRIGGER);" Works
    2. "ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer)ADC_TRIGGER_1);" ERROR WHEN ATTEMPTED TO EXECUTE/TASK BLOCKED AT THIS POINT
    3. "ioctl(f, ADC_IOCTL_RUN_CHANNEL, (pointer)ADC_PDB_TRIGGER);" Works
    4. "ioctl(f, ADC_IOCTL_RUN_CHANNEL, (pointer)ADC_TRIGGER_1);" Works
    5. "ioctl(f, ADC_IOCTL_RUN_CHANNELS, (pointer)ADC_PDB_TRIGGER);" Works
    6. "ioctl(f, ADC_IOCTL_RUN_CHANNELS,(pointer)ADC_TRIGGER_1);" ERROR WHEN ATTEMPTED TO EXECUTE/TASK BLOCKED AT THIS POINT
  4. Optionally open a second channel in the ADC that references the lwevent I created (with a different trigger).  Opening the channel does not return an error but the lwevent is not returned for any of the following triggers:
    1. "ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer)ADC_PDB_TRIGGER);" No Error for this ioctl but "_lwenvent_wait_ticks" never returns
    2. "ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer)(ADC_TRIGGER_1 | ADC_TRIGGER2));" ERROR WHEN ATTEMPTED TO EXECUTE/TASK BLOCKED AT THIS POINT
    3. "ioctl(f, ADC_IOCTL_RUN_CHANNEL, (pointer)ADC_PDB_TRIGGER);" No Error for this ioctl but "_lwenvent_wait_ticks" never returns
    4. "ioctl(f, ADC_IOCTL_RUN_CHANNEL, (pointer)(ADC_TRIGGER_1 | ADC_TRIGGER2));" No Error for this ioctl but "_lwenvent_wait_ticks" never returns
    5. "ioctl(f, ADC_IOCTL_RUN_CHANNELS, (pointer)ADC_PDB_TRIGGER);" No Error for this ioctl but "_lwenvent_wait_ticks" never returns
    6. "ioctl(f, ADC_IOCTL_RUN_CHANNELS, (pointer)(ADC_TRIGGER_1 | ADC_TRIGGER2));" No Error for this ioctl but "_lwenvent_wait_ticks" never returns
  5. Trigger the ADC using the ioctl commands listed above in steps 3 & 4.
  6. Execute an infinite loop while waiting on the lwevent - which never returns for the case where I open both channels.  The statements used (for both channels) is:
    1. "_lwevent_wait_ticks(&evn1, ADC_TRIGGER_1 | ADC_TRIGGER_2, FALSE, 0);"

 

I have looked through the MQX forum here and while I have found people with similar problems and some sample solutions, but I haven't found one that is right for my application.  I guess the worst-case solution is to close a channel after reading it and then opening another on the ADC, but I would think that I should be able to get multiple ADC channels operating in a task - correct? 

 

I have attached the code that I am using - maybe somebody has an idea why I am having this problem. 

 

Finally, what is the limit to the number of channels that can be opened for an ADC simultaneously?  When I looked through the forums it look like it is limited by ADC_MAX_CHANNELS, but when I tried to change this define in the bsp, the rebuild fails.  Any comments? 

 

Thanx,

 

myke

Original Attachment has been moved to: adc_task.h.zip

Original Attachment has been moved to: adc_task.c.zip

Outcomes