Hi,
I have some trouble with the ADC on the LPC55S16.
Our usecase:
- Using the internal temperature
- Using several ADC channels, both A side and B side (all in single ended mode).
For easy integrating in our current codebase, we want to:
- Have a trigger command for each individual ADC channel
- Trigger the command individually (by our SW)
- Use polling to get the ADC result.
When I implemented this, the ADC values were jumping all over the place, like they ended up in the wrong (random) ADC variables.
E.g.: when I did 3 channels (ADC0, ADC1, ADC2), the results were like:
| valueADC0 | valueADC1 | valueADC2 |
| ADC1 | ADC0 | ADC2 |
| ADC0 | ADC2 | ADC1 |
| ADC2 | ADC1 | ADC0 |
| ADC1 | ADC0 | ADC2 |
| ADC0 | ADC2 | ADC1 |
So I tried to reproduce this on me LPCXpresso55S16 development board.
I used the lpadc_temperature_measurement example as basis, with the following changes:
- I removed the GETCHAR() macro, and replaced it with a 1 second delay (to get results continuously, like in our application)
- Removed the interrupt handling, and made it polling (copied from lpadc_polling example)
- Used the CommandID also as TriggerID (so I could easily distinguish later between several ADC channels)
- Created a seperate function for the channel configuration, which I could easily copy later on for other channels.
After those changes the example still worked correctly (although temperature measurement needs some additional work, as there is a lot of digital noise due to low resolution of the vbe ADC values, but that's another topic):

Now I added ADC channel ADC0_0 (PIO0_23):
- Added pin config in pinmux.c (copied from lpadc_polling example)
- Copied the Temperature sensor config function (mentioned above), and changed it for ADC0_0:
- channelNumber = 0
- sampleChannelMode = kLPADC_SampleChannelSingleEndSideA
- New CommandID (2) and also use it as triggerID
- loopCount = 0
- After the Temperature sensor trigger and getting the temperature, I added a new trigger (LPADC_DoSoftwareTrigger) with the new triggerID (mask).
- Added the result to the terminal output.
This is what I get:

As you can see the first temperature result looks OK, but after that it's way off.
(I didn't check the ADC0_0 result, but that also looks off, as nothing is connected to the pin yet)
I attached my MCUXpresso project, can you please have a look what I'm doing wrong?
I can't find any example using multiple channels or ADC commands.
I can't figure it out...
It looks like there's something going wrong in the FIFO, but I can only see the top value...
Thanks in advance.
Best regards