Listen F4 adc1 simulate the watchdog [database function operation]

Source: Internet
Author: User

The analog watchdog of the ADC is used to check whether the voltage is out of bounds. It has two upper and lower boundaries, which can be set in registers adc_htr and adc_ltr respectively. Library functions are set using adc_analogwatchdogthresholdsconfig. both conventional and injection channels are simple.

When the simulated watchdog detects that the voltage is higher than or below the upper limit, the watchdog is interrupted. Capture the interrupt and take some countermeasures.

A special thing in the Data Manual: the comparative data used by the simulated watchdog is irrelevant to the Data Alignment set in the adc_cr2 register. The comparison of the watchdog is completed before data alignment. First compare the watchdog, and then put the data into the adc_dr data register.

In the st library, there are only three simple functions related to the watchdog:

Void adc_analogwatchdogcmd (adc_typedef * adcx, uint32_t adc_analogwatchdog );
Void adc_analogwatchdogthresholdsconfig (adc_typedef * adcx, uint16_t highthreshold, uint16_t lowthreshold );
Void adc_analogwatchdogsinglechannelconfig (adc_typedef * adcx, uint8_t adc_channel );

Use adc_analogwatchdogthresholdsconfig to set the upper and lower limits for triggering the Watchdog

Use adc_analogwatchdogsinglechannelconfig to configure the channel to use a simulated Watchdog

After the configuration is complete, use adc_analogwatchdogcmd to start the simulated watchdog.

The function I wrote is very simple, just three rows. Add the simulated watchdog to the worker of adc1.CodeAs follows:

Void adc_watchdogconfig (void)
{
Adc_analogwatchdogsinglechannelconfig (adc1, adc_channel_0 );
Adc_analogwatchdogthresholdsconfig (adc1, 1500,0 xfff );
Adc_analogwatchdogcmd (adc1, adc_analogwatchdog_singleregenable );
}

Initialize the simulated watchdog in Objective C:

Void nvic_config (void)
{
Nvic_prioritygroupconfig (nvic_prioritygroup_2); // sets the interrupt priority group.
Nvic_initstructure.nvic_irqchannel = adc_irqn;
Nvic_initstructure.nvic_irqchannelcmd = Enable;
Nvic_initstructure.nvic_irqchannelpreemptionpriority = 0x01;
Nvic_initstructure.nvic_irqchannelsubpriority = 0x00;
Nvic_init (& nvic_initstructure );
}

Capture watchdog interruption:

Void adc_irqhandler (void)
{
Adc_itconfig (adc1, adc_it_awd, disable );
If (set = adc_getflagstatus (adc1, adc_flag_awd ))
{
Adc_clearflag (adc1, adc_flag_awd );
Adc_clearitpendingbit (adc1, adc_it_awd );
Printf ("adc awd is happened. \ r \ n ");
}
Adc_itconfig (adc1, adc_it_awd, enable );
}

Of course, do not forget to enable the ADC interruption:

Adc_itconfig (adc1, adc_it_awd, enable );

Technorati flag: 127f4, ADC, watchdog, analog Watchdog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.