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