Using Two A/D's FRDM-K22F

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

Using Two A/D's FRDM-K22F

529 Views
briancavanagh
Contributor III

I created a program using one A/D (i know my question above states 2) and based on whether the A/D value is < 0x7fff (turn Red led on) and if the A/D value is >0x7fff (turn Yellow led on).

Now that I'm using two A/D's, I see a pointer is being used for each stored A/D value.

I'm not sure how to read "value[0]" and "value[1]".  I will use two leds for "value[0]" result, and another two for "value[1]" result.  The Red and Yellow criteria will be the same as above.

I commented out my LED-Code so I can step-through the program and observe what happens during the A/D process. 

Here's what I observed:

When I hovered over 'word' (in red) the 'value' was 0x0000 which is correct, since I adjusted pot1 so the input pin will read 0 volts. 

Likewise, when I hovered over 'word' (in blue) the 'value' was approximately 0xffff which is correct, since I adjusted pot2 so the input pin will read 3.3 volts.

pastedImage_1.png

This confirmed to me, that the program I created using two A/D's is working correctly.

Here's my struggle:

I'm not clear how to use the result from "value[0]", then light the led that determines if it's less than or greater than 0x7fff.  Similarly, the same holds true how to read "value[1]".

Below is my code for a successful measurement with two A/D channels.  You'll notice I have the LED-code commented out that was related to my single channel led test.  Of course, the uncommented code does not reflect the single channel A/D I used previously.

pastedImage_2.png

            Note:  I overlapped (void)AD1_GetValue16(&value[0]) in the screen capture for clarity to the reader.

                       Also, you will notice, below, in the commented code, how I determined whether the Red or Yellow                         led should turn on/off based on the A/D measurement.  This code did work for the signal A/D                         measurements.

pastedImage_3.png

Thanks,

Brian

Tags (3)
0 Kudos
2 Replies

423 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Please try to test the code below:

word value[AD1_CHANNEL_COUNT];

  while(1)
  {
    AD1_Measure(TRUE);
    AD1_GetValue16(value);
    if(value[0]>0x7ff)Bit1_SetVal(bit1Ptr);
    else Bit1_ClrVal(bit1Ptr);
    if(value[1]>0x7ff)Bit2_SetVal(bit2Ptr);
    else Bit2_ClrVal(bit2Ptr);
  }

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

423 Views
bobpaddock
Senior Contributor III

I did not analyze all of your code, look for places where an address is being used where a value is needed or the other way around.

Note that in C for an array 'value' and &value[0] return the same address.

if( &value > 0x7FF )

Should read:

if( value[0] > 0x7FF )