I am using the onboard ADC on a KL02Z microcontroller,
I am trying to read ADC channel 0 and ADC channel 13 (other channels have been used for other functions)
I assume this is possible?
If you go through the chip configuration chapter and see section 126.96.36.199.1, you will notice that to use ADC0_SE13, you have to assign channel 16 in ADC0_SC1. Assigning channel 13 infact scans ADC0_SE10. However it has nothing to do with triggering. Software as well as hardware triggering must bear no effect on a constant voltage scan.
I guess you don't want to change the channels, so you can do the ADC0_SC1A as one time setting in your init. You must however take care of clearing the COCO flag inside your ADC ISR. You must select ADC0_SC2_ADTRG bit for hardware triggering.
Note: Please mark the reply as helpful/correct if it helps.
Yes you can use the two channels for analog measurement. The same can be set in ADCx_SC1n registers and the results can be read in Rn Data registers.
For further details you can go through the Functional description module for ADC in the KL02 Sub-Family Reference Manual.
Let us know if this does not solve your question or in case you need any further assistance.
Thanks for the response. Is there anything unusual about channel 13 on the FRDM-KL02Z?
I can read channel 0 fine. I can read channel 13 (or at least I believe its 13), however if I tie the pins for channel 13 down to 0V the ADC values still shows a floating voltage level. I am using PTB13 for channel 13, which is J10 pin 3 on the FRDM-KL02Z.
To read channel 13 I am triggering the conversion with:-
ADC0_SC1A = ADC_SC1_AIEN_MASK | ADC_SC1_ADCH(13);
PORTB_PCR13 |= PORT_PCR_MUX(0); // ADC use
Any idea why the ADC is not changing if I ties the pin to 0V?
Maybe I am triggering incorrectly. I am using TPM1 to HW trigger the ADC on an overflow.
In my ADC ISR I am reading the result from the ADC channel and then kicking off the conversion for the next ADC channel. On the next ADC ISR I grab the ADC result from the previous conversion and kick off the next channel conversion etc......
I'm kicking off the conversion with
ADC0_SC1A = ADC_SC1_AIEN_MASK | ADC_SC1_ADCH(channel);
Do I need to do this for HW triggering, only it seems the same as I what I used fro SW triggering ?
Thanks for your help. You have cleared up some things for me.
I'm still a little confused though. I do have HW triggering setup and my ADC ISR is being triggered. My aim is to trigger 4 channels. I was kicking of the first channel in my ADC init with
ADC0_SC1A = ADC_SC1_AIEN_MASK | ADC_SC1_ADCH(0);
This seems to work fine. In my ADC ISR I read the value from ADC0_RA when the ISR is called and the conversion is complete.
I then wanted to start to the conversion for my next channel from within the ADC ISR e.g. channel 13. I am currently doing this with the following line of code(in reality I'm stepping through a table that hold the channels I want to read. I repeat and keep going around my table, so I'm constantly reading my 4 channels.):
This however seem to be the way to generate a SW trigger and not HW trigger. So I guess my question is how do I setup the next channel for HW trigger in my ADC ISR? Am I already doing this correctly or not?
Thanks for your help. It is appreciated.
Going by your needs it seems a bit inappropriate that you are using a hardware trigger. Since you are scanning 4 channels, enabling hardware trigger would mean that at every trigger one of the samples get scanned, which in effect means that to scan 4 channels you would be taking 4 triggers or 4 TPM periods. A software trigger would be much quicker, and you can keep changing the channels just the way you are doing correctly. If not hardware triggered, the write to SCx register would generate soft trigger. Please make the decision based on your application requirement.
Thanks you for you help and advice. So it seems my method to setup the channel with HW trigger is correct then?
My original intent was to use SW trigger and do exactly as you mention. I was reading 4 channels subsequently in my TPM ISR.
I have a lot of other stuff going on in my code and I couldn't really afford the additional overhead of reading all 4 channels in one hit, hence my move to using the ADC ISR and TPM to trigger the ADC, thus avoiding waiting for conversions to complete.
It all seems to work, so I guess my setup is correct.
Using channel 16 instead of 13 for ADC0_SE13 was one of my real issues. You cleared this up for me and this was an oversight in my part.
Good to see that things working as expected. Feel free to post for any further questions. Happy debugging.
Retrieving data ...