How to trigger ADC back to back conversion periodically?

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

How to trigger ADC back to back conversion periodically?

1,817 Views
m_weber
Contributor I

Hi,

I am new to the S32K Environment. I have bought an S32K116 Evaluation Board on which i am trying to sample 6 ADC Channels at a sample rate of 20ksps. In the end i'd like to pass thoose raw values to another microcontroller via UART, but i am currently stuck at setting the sample rate.

I have enabled the first 6 PDB0 channels (conversions are triggered back to back) and ADC0 channels. The PDB is triggered by Software and supposed to run in continuous mode and trigger the adc conversion every 50us. I calculated the conversion time to be around 1us per channel(~6us). The ADC Clock and PDB Clock are both 48MHz.

Somehow my timing is not right. I do get a PDB Channel Sequence Error. If i change the PDB->MOD to a higher value the error disappears and conversion works. Why cant I trigger the Conversion every 50us?

Also I am quite confused with all of the pre trigger stuff. Do I need to change some of the Delays?

I have attached my code below. Thanks in advance for your help.

Max

Labels (1)
0 Kudos
Reply
2 Replies

1,745 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Max,

setting looks normal, the issue will be due to reading the ADC result is not done in time. You should read ADC result registers before new pretriggers happens, otherwise lock condition happens and you got sequence error. This is described in chapter 46.4.1 of the RM.

Because you print out result after each COCO is set, it adds delay for reading result registers. If you increase PBD modulo, you probably read all in time, before new period happens.

Try to rewrite a code. Check just last COCO flag in chain and read all result registers. Do not print all each period or be sure it is finished in time.

BR, Petr

1,745 Views
m_weber
Contributor I

Hey Petr,

thank you very much for your quick answer! I was able to solve my problem with your note.

I had the ADC0->SC1[AIEN] Interrupt enabled for every channel. This threw way to many interrupts and added a significant delay. The interrupt is only enabled for the last channel now and i am checking the last COCO Flag only but reading all the necessary result registers.

I also figured i could ignore all the PDB delays, especially the PDB0->DLY because I am not using the PDB Interrupt.

Best regards,

Max

0 Kudos
Reply