CMP1_IN3 Not working on FRDM-K64F

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

CMP1_IN3 Not working on FRDM-K64F

702 Views
knovinger
Contributor III

I'm working with the FRDM-K64F and the cmp_polling driver example provided with the SDK (ver 2.4.2) .  The example works perfectly as is, but i'm trying to reconfigure the example to use CMP1_IN3 and have been unsuccessful.

It's my understanding this is a default port and it's first come/first serve on the mode of operation (i.e. DAC0_OUT/CMP1_IN3/ADC0_SE23).  That said, all I've done to the example is modify pin_mux.c with the PIN_TOOL to remove the initial configuration of PTC7 as CMP0_IN1.  Then, i just changed the define statement to point to CMP1, channel 3.

Are there some additional configurations that need to set for this particular input to work?

To me, the datasheets and reference manuals are unclear in what they mean by a single pin having the functions DAC0_OUT/CMP1_IN3/ADC0_SE23.

2018-10-12 16_07_03-K64P144M120SF5.pdf - Adobe Reader.png

0 Kudos
2 Replies

527 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Kevin Novinger,

Please try modify the value of DEMO_CMP_BASE and DEMO_CMP_USER_CHANNEL.

CMP1_IN3.png

Best Regards,

Robin

 

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

0 Kudos

527 Views
mjbcswitzerland
Specialist V

Hi Kevin

The pin in question is simply a pin connected to the three peripherals at the same time.

Out of reset the DAC is disabled and so is not driving this output, meaning that it has two functions in parallel - ADC0_SE23 and CMP1_IN3 and means that you can read the value on the pin by reading the ADC and you can also use the same input as comparator input (at the same time since two inputs in parallel don't disturb each other).

If you enable the DAC it will drive a voltage on the pin, which is then the input voltage seen by the ADC and the CMP. In this case the pin can be considered as an output and so would not be connected to external circuitry driving it.

I have attached a FRDM-K64F binary that you can load to your board. It will read the ADC_23 input every 3s and print the value to the OpenSDA VCOM (115kBaud). It also sets up the CMP1 as you have done so and gives messages each time the comparator detects a falling or rising event. The comparator output is enabled (PTB21 - the blue LED) so the comparator state can also be observed/measured).
Finally, in the debug menu on the VCOM you can enter the HW menu and command DAC output values: "dac 0 fff", for example, would set max output signal. When this command is used it also enables the DAC so that it starts driving the pin, and its voltage is measured on ADC_23 and controls the CMP positive input.

This is the CMP code that I use in the uTasker project which does everything automatically and I didn't see any complications with CMP1_IN3. It is much easier to use (and more power-ful) than the examples you modified (which is more error prone). Here the CMP is simply changed by modifying the comparator_setup.comparator value:

static void fnConfigureComparator(void)
{
    COMPARATOR_SETUP comparator_setup;                                   // interrupt configuration parameters
    comparator_setup.int_type = COMPARATOR_INTERRUPT;                    // identifier when configuring
    comparator_setup.int_priority = PRIORITY_COMPARATOR;                 // comparator interrupt priority
    comparator_setup.int_handler = comparator_trigger;                   // interrupt call-back
    comparator_setup.comparator = 1;                                     // comparator 1
    comparator_setup.comparator_mode = (COMPARATOR_BUS_CLOCK | COMPARATOR_HYSTERISIS_LEVEL_0 | COMPARATOR_HIGH_SPEED_MODE |
                                        COMPARATOR_OUTPUT_ENABLE | COMPARATOR_OUTPUT_UNFILTERED |
                                        COMPARATOR_INTERRUPT_RISING_AND_FALLING |
                                        COMPARATOR_DAC_ENABLE | COMPARATOR_DAC_VOLTAGE_VDD |
                                        COMPARATOR_ENABLE);
    comparator_setup.filter = 0;                                         // filter sample count(1..7) in external sampling mode or 0..255 in bus clock mode
    comparator_setup.DAC_level = 31;                                     // half-voltage reference generated
    comparator_setup.positive_input = COMPARATOR_IN3;                    // positive input
    comparator_setup.negative_input = COMPARATOR_IN_DAC_OUT;             // negative input
    fnConfigureInterrupt((void *)&comparator_setup);                     // start operation
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is a reference debug output session showing the ADC value being periodically output and some falling/rising CMP detections when I apply 0V/3V3 to the pin.
I then enter the HW menu and command some DAC 0 output values, which are measured by the ADC and also cause further CMP rising/falling detections when the values cross the CMP threshold (with hysterisis):


Hello, world... FRDM-K64F [External]
Static memory = 0x00000884
OS Heap use = 0x02b9 from 0xfc00
Initial stack margin 0x0000f9e8
ADC triggered: 0x01bf
ADC triggered: 0x01ee
ADC triggered: 0x0231
ADC triggered: 0x0219
ADC triggered: 0x021d
ADC triggered: 0x015f
CMP-1 = Rising
ADC triggered: 0x0fff
ADC triggered: 0x0fff
CMP-1 = Falling
ADC triggered: 0x0005
ADC triggered: 0x0001
ADC triggered: 0x012f

Serial number: 00
Software version V1.4.012
Device identification: KINETIS

     Main menu
===================
1              Configure LAN interface
2              Configure serial interface
3              Go to I/O menu
4              Go to administration menu
5              Go to overview/statistics menu
6              Go to USB menu
7              Go to I2C menu
8              Go to utFAT disk interface
9              FTP/TELNET commands
a              CAN commands
b              Advanced commands
help           Display menu specific help
quit           Leave command mode
ADC triggered: 0x01ea
3


 Input/Output menu
===================
up             go to main menu
md             Memory Display [address] [<l>|<w>|<b>] [num]
mm             Memory Modify [address] [<l>|<w>|<b>] [val]
mf             Memory Fill [address] [<l>|<w>|<b>] [val] [num]
sd             Storage Display {as md}
sm             Storage Modify {as mm}
sf             Storage Fill {as mf}
se             Storage Erase [address] [len-hex]
set_ddr        Set port type [1..4] [<i>|<o>
get_ddr        Get data direction [1..4]
read_port      Read port input [1..4]
write_port     Set port output [1..4] [0/1]
dac            DAC [ref] [hex]
save           Save port setting as default
help           Display menu specific help
quit           Leave command mode

ADC triggered: 0x01e3
ADC triggered: 0x0167
ADC triggered: 0x0224

dac 0 fff

#CMP-1 = Rising
ADC triggered: 0x0ffb

ADC triggered: 0x07fd
ADC triggered: 0x07fc
dac 0 900

#CMP-1 = Rising
ADC triggered: 0x08fd
ADC triggered: 0x08fd
dac 0 700

#CMP-1 = Falling

dac 0 900

#CMP-1 = Rising
dac 0 700

#CMP-1 = Falling
ADC triggered: 0x06fc
ADC triggered: 0x06fc

As reference, here are the register values used to setup CMP1 [using interrupts on both rising and falling senses] so that you can work out what is missing in your code (there are no further settings needed).

pastedImage_3.png

Regards

Mark

Simulation of K64 in uTasker environment showing the pin functions and allowing verification of the complete operation:

pastedImage_4.png

0 Kudos