ADC interrupt / compare function

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

ADC interrupt / compare function

Jump to solution
1,264 Views
pascalschröer
Contributor V

Hi to everybody,

I'm using a Kinetis MK10DX128VLH7 uC and would like to monitore an ADC value in bachground.

If the value is not in the calculated area, I would like to generate an interrupt.

To do this, I initialised the internal ADC0 with continous mode and the specific sample parameters.

Well, the initialisation and the interrupt works but I can only generate an interrupt when the calculated

value is reached, NOT if the value is beyond my calculated borders. (The datasheet says the same)

//Now I generate an interrupt when my calculated value is reached

ADC0_CV1 = 0x6000;

ADC0_CV2 = 0x5000;

So, am I right just to switch the two values like this??

//Now I would like to generate an interrupt only when the ADC value is beyond my calculated area

ADC0_CV2 = 0x6000;

ADC0_CV1 = 0x5000;

That seems to work but I'm not able to verify it in the moment...

Maybe someone can say me the rules for generating an interrupt

based on the two CV values.

Thanks :smileyhappy:

Pascal

0 Kudos
1 Solution
886 Views
apanecatl
Senior Contributor II

If you are using the range comparison you have 2 different modes:

  • Inside range
    • A dual comparison is performed and if the input value is within the defined threshold values (ADCx_CV1, ADCx_CV2) and the interrupt trigger enabled, an interrupt will be generated by the comparison, the COCO flag will be set and the result will be transferred to the result register.

  • Outside range
    • A dual comparison is performed and if the input value is outside the defined threshold values (ADCx_CV1, ADCx_CV2) and the interrupt trigger enabled, an interrupt will be generated by the comparison, the COCO flag will be set and the result will be transfered to the result register.

When using the inside/outside range comparison you will have two different settings:

  • Inclusive
    • When the comparison is performed, the fringe values (ADCx_CV1, ADCx_CV2) are taken into consideration.

  • Not inclusive
    • When the comparison is performed, the fringe values (ADCx_CV1, ADCx_CV2) are not taken into consideration; only greater or lesser values.

View solution in original post

0 Kudos
4 Replies
886 Views
apanecatl
Senior Contributor II

I would instead use the Greater than or equal to threshold  function to generate an interrupt when the analog input reaches your threshold value; for the range comparison I would use the Outside range, inclusive function instead of changing the compare threshold (ADC0_CV1, ADC0_CV2).

0 Kudos
886 Views
pascalschröer
Contributor V

Thanks for your answer!

I'm not sure, if I understand the text in the data sheet right:

http://cache.freescale.com/files/32bit/doc/ref_manual/K10P64M72SF1RM.pdf

Refer to page 704:

Configures less than threshold, outside range not inclusive and inside range not inclusive; functionality based on the values placed in CV1 and CV2.

Does it means that I only generate an interrupt, if my measured value is

     1. smaller than the CV1 value or

     2. taller than the CV2 value??

I can't find this meaning in the text....

Thanks

Pascal

0 Kudos
887 Views
apanecatl
Senior Contributor II

If you are using the range comparison you have 2 different modes:

  • Inside range
    • A dual comparison is performed and if the input value is within the defined threshold values (ADCx_CV1, ADCx_CV2) and the interrupt trigger enabled, an interrupt will be generated by the comparison, the COCO flag will be set and the result will be transferred to the result register.

  • Outside range
    • A dual comparison is performed and if the input value is outside the defined threshold values (ADCx_CV1, ADCx_CV2) and the interrupt trigger enabled, an interrupt will be generated by the comparison, the COCO flag will be set and the result will be transfered to the result register.

When using the inside/outside range comparison you will have two different settings:

  • Inclusive
    • When the comparison is performed, the fringe values (ADCx_CV1, ADCx_CV2) are taken into consideration.

  • Not inclusive
    • When the comparison is performed, the fringe values (ADCx_CV1, ADCx_CV2) are not taken into consideration; only greater or lesser values.
0 Kudos
887 Views
pascalschröer
Contributor V

Hi,

okay thanks for your explanation! Now, it's clear!

I have probably skiped page 728 :smileywink:

Thanks a lot!

Pascal