2928 views|3 replies

1w

Posts

26

Resources
The OP

[SAM R21] Comparator test [Copy link]

Yesterday I tried the comparator and ADC functions of SAM R21 again. Let me talk about the use of the comparator first. From the data sheet, we can see that the comparator uses the PA04-PA07 pins, while the ADC uses the PA04-PA09 pins. In the comparator example in ASF, we can see that the main settings are in the configure_ac_channel function.
  1. void configure_ac_channel(void) //! [setup_7] { /* Create a new configuration structure for the Analog Comparator channel * settings and fill with the default module channel settings. */ //! [setup_8] struct ac_chan_config ac_chan_conf; //! [setup_8] //! [setup_9] ac_chan_get_config_defaults(&ac_chan_conf); //! [setup_9] /* Set the Analog Comparator channel configuration settings */ //! [setup_10] ac_chan_conf.sample_mode = AC_CHAN_MODE_SINGLE_SHOT; ac_chan_conf.positive_input = AC_CHAN_POS_MUX_PIN0; ac_chan_conf.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; ac_chan_conf.vcc_scale_factor = 32; //! [setup_10] /* Set up a pin as an AC channel input */ //! [setup_11] struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PA04B_AC_AIN0; system_pinmux_pin_set_config(PIN_PA04B_AC_AIN0, &ac0_pin_conf); //! [setup_11] /* Initialize and enable the Analog Comparator channel with the user * settings */ //! [setup_12] ac_chan_set_config(&ac_instance, AC_COMPARATOR_CHANNEL, &ac_chan_conf); //! [setup_12] //! [setup_13] ac_chan_enable(&ac_instance, AC_COMPARATOR_CHANNEL); //! [setup_13] } //! [setup]
复制代码
It uses AIN0 as the positive input of the comparator, corresponding to PA04. Therefore, when doing the comparator experiment, we connect the input of the comparator to PA04 on the EXT1 interface. The negative end of the comparator uses the voltage divider of VCC as input, and the voltage divider coefficient is 32, that is, 32/64=1/2Vcc. If you modify the voltage divider coefficient, you can get different comparison thresholds. If you change the input of the comparator, you can use different GPIOs. LED0 represents the output of the comparator. You can easily observe the output status of the comparator by adjusting the potentiometer.



This post is from Microchip MCU

Latest reply

Learn  Details Published on 2014-12-19 16:28

1068

Posts

7

Resources
2
Like
This post is from Microchip MCU

3407

Posts

0

Resources
3
Very strong, I have learned
This post is from Microchip MCU
Personal signature

So TM what......?


79

Posts

1

Resources
4
Learn
This post is from Microchip MCU

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list