ADC ADC_CHANNEL_MEASURE_LOOP doesn't seem to work

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

ADC ADC_CHANNEL_MEASURE_LOOP doesn't seem to work

Jump to solution
1,127 Views
LPs
Contributor III

Hi all,

   I'm trying using MQX ADC driver. I installed it with these parameters

// Struttura di inizializzazione del canale ADC utilizzato per i tasti freccia

const ADC_INIT_CHANNEL_STRUCT g_keyboardADCInitParams =

{

    KEYBOARD_ADC_CHANNEL, // physical ADC channel

    ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_NOW, // free running samples starts after fopen

    KEYBOARD_ADC_N_SAMPLES,             // number of samples in one run sequence

    0,         // time offset from trigger point in us

    KEYBOARD_ADC_PERIOD,         // period in us ()

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

    KEYBOARD_ADC_N_SAMPLES,             // circular buffer size (sample count)

    ADC_PDB_TRIGGER,     // logical trigger ID that starts this ADC channel

#if MQX_USE_LWEVENTS

    &g_keyboardEvent,

    KEYBOARD_ARROWS_EVENT // mask of event to be set

#endif

};

In that way all is working, but if I change the flags to ADC_CHANNEL_MEASURE_LOOP the event is triggered once and after the first conversion no more event is set.

What I'm doing wrong?

0 Kudos
1 Solution
606 Views
c0170
Senior Contributor III

Hello lucapetro,

what version of MQX are you using? There was a problem with PDB triggering, explained here:

https://community.freescale.com/thread/302405

I am not aware how is PDB and debugging in the current MQX version (4.0.1).

Regards,

c0170

View solution in original post

0 Kudos
6 Replies
606 Views
c0170
Senior Contributor III

Hello lucapetro,

please read How to post in the MQX section and get an answer!

what is missing here is your target MCU and at least some code which shows what is your code executing?

Event's are set inside function _adt_process_data which is in adt_kpdb.c (for kinetis).

Regards.

c0170

0 Kudos
606 Views
LPs
Contributor III

Sorry,

  I'm developing on K10 device.

Mi code install the event and waits for the end of convertion to evaluate the ADC value.

This is my init function

   g_keyboardADCFile = fopen("adc1:", (const char*)&adc_init);

  if (g_keyboardADCFile != NULL)

  {

    g_keyboardADCChannelFile = fopen("adc1:KBD_ARROWS", (const char*)&g_keyboardADCInitParams);

  if(g_keyboardADCChannelFile != NULL)

  {  

  retVal = TRUE; 

  }

  }

This is the event creation

if (_lwevent_create(&g_keyboardEvent, LWEVENT_AUTO_CLEAR) != MQX_OK)

{

     _task_block();

}

My task watis for event

eventRetVal = _lwevent_wait_ticks(&g_keyboardEvent, 0xFFFFFFFF, FALSE, 0);

606 Views
LPs
Contributor III

I found out something.

The ADC LOOP works well. The problem is that after a Breackpoint (I'm using IAR and SEGGER j-link), the adc stops to call events and my task is always waiting.

Do someone knows how to set ADC to continue working after a breakpoint?

0 Kudos
607 Views
c0170
Senior Contributor III

Hello lucapetro,

what version of MQX are you using? There was a problem with PDB triggering, explained here:

https://community.freescale.com/thread/302405

I am not aware how is PDB and debugging in the current MQX version (4.0.1).

Regards,

c0170

0 Kudos
606 Views
LPs
Contributor III

Thank you very much.

That is happening to me.

I'm working with MQX 4.0.1, SEGGER JLink debugger and IAR workbench.

I think I'll change my code, It's not possible for me to debug with this problem.

I have another question: if I use HW TRIGGER option, I must use ioctl function to trigger a new convertion or there is an HW event that can use the trigger?

0 Kudos
606 Views
LPs
Contributor III

At the end I solved my problem using a timeout on the _lwevent_wait_ticks.

My adc takes 50ms for a complete convertion. I set the timeout of event semaphore to 100 mS.

If lwevent_wait_ticks return with value LWEVENT_WAIT_TIMEOUT:

  1. Close ADC channel and ADC module files.
  2. Reset PDB0_CH1S register to clear the error flag of PDB timer
  3. Reopend ADC channel and ADC module file.

In this way after a breakpoint the firmware trigger the problem and restart the ADC correctly.

Could be a runtime faultback in case of spurious error on PDB.

Hope can help someone.

Bye