Question to K60 ADCs in use with PDB

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

Question to K60 ADCs in use with PDB

982 Views
chn
Contributor I

Hello,

I have a question about using PDB with ADCs on a Kinetis K60.

My system is as follows:

ADC0, A-channel must be converted every 1 ms
ADC1, A-channel must be converted every 10 ms
ADC1, B-channel must be converted every 10 ms

So I initialized PDB for running with 1 ms and enable ADC1 pre-trigger in every 10th PDB interrupt service routine..
It seems to work, but I don't know if this is a safe way to do that. My code for the pdb-isr is as following:

void pdb_isr( void )

{
  PDB0_SC &= ~PDB_SC_PDBIF_MASK;
 
  static intx cntPDB = 0;
  if( ++cntPDB == 10 )
  {
    cntPDB = 0;
    PDB0_CH1C1 = PDB_C1_EN(0x01) | PDB_C1_TOS(0x01) | PDB_C1_EN(0x02) | PDB_C1_TOS(0x02);
  }
  else
  {
    PDB0_CH1C1 = 0;
  }
}// end of HwADC_PDBISR()

Labels (1)
Tags (3)
0 Kudos
3 Replies

545 Views
chn
Contributor I

Hi Mark,

thanks for your response.

Yes I know, that I have to use PDB. If your remarks for B channel is to question 3:

I wanted to say that triggers for conversion come correct from PDB, but in the adc1_isr routine, when getting the isr for B channel I read also the A-channel value, if I don't switch the cahnnels with MUXSEL before as in my posted code. But his I have never seen in examples from internet (that don't work for me).

Am I doing something wrong?

The glitches when using ADC0 with timerinterrupt and ADC1 with PDB were on the values for ADC1.

0 Kudos

545 Views
mjbcswitzerland
Specialist V

Hi Christine

If there are gitches on the ADC1 value(s) it probably means that the conversion is either not complete when you read the value or it is being disturbed by the enable/disable process (or its conversion time is longer than the 1ms period).

My feeling is that it would be best to use the PDB with a 10ms cycle so that it suits ADC1 (channels A and B) and use a 1ms timer for ADC0. ADC0 can be set to free-running mode and the 1ms timer can be used to read it. This way there is no risk of disturbing ADC1 PDB operation. Also the ADC1 conversion parameters can be set to highest averaging since it can take longer and so the optimal convesion accuracy be obtained.

Since you already use a 1ms interrupt there is no increase in interrupt overhead involved.

Regards

Mark

Kinetis: µTasker Kinetis support

K60: µTasker Kinetis TWR-K60N512 support / µTasker Kinetis TWR-K60D100M support / µTasker Kinetis TWR-K60F120M support

ADC/DAC: http://www.utasker.com/docs/uTasker/uTaskerADC.pdf

For the complete "out-of-the-box" Kinetis experience and faster time to market

545 Views
mjbcswitzerland
Specialist V

Hi Christine

Using ADC1 A and B requires HW triggering mode otherwie only the A channel can be used. This means that you need to use the PDB triggering it at 10ms and not use an interrupt routine to read it (it can't trigger B channel conversions).

I don't known why you have glitchs on ADC0 since a 1ms interrupt read should be OK. However you could instead try using DMA to store the ADC0 channe value at 1ms rate to a buffer and then at each 10ms PDB interrupt you can process the 10 ADC0 values and the ADC1 A and B values (assuming that the ADC operatio works around the cause of the glitches).

Regards

Mark

Kinetis: µTasker Kinetis support

K60: µTasker Kinetis TWR-K60N512 support / µTasker Kinetis TWR-K60D100M support / µTasker Kinetis TWR-K60F120M support

ADC/DAC: http://www.utasker.com/docs/uTasker/uTaskerADC.pdf

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos