Power supply voltage monitoring is also a common module for MCU. When we need stable industrial products, we often need to monitor the power supply voltage to ensure that the SCM system works in the normal environment or range. Msp430f16x provides a ready-made power supply voltage monitor module SVS, which is convenient to detect the power supply voltage or external voltage. It can be set to reset or set the flag when the voltage is too low. This program is to complete the SVS settings using the library (msp430f14x does not have this module).

Hardware introduction:

MSP430 MCU contains SVS module, which can easily monitor the power supply voltage or external voltage.

The power supply voltage monitor (SVS) is used to monitor the avcc power supply voltage or external voltage. SVS can be configured to set a flag or generate por reset when the supply voltage or external voltage drops below the voltage level selected by the user.

SVS module has the following features: it can monitor avcc voltage; it can generate reset signal; it can set SVS comparator output signal by software; low voltage flag can be locked or accessed by user program; it has 14 voltage thresholds to choose from; it can monitor external input voltage. SVS module can easily monitor the power supply voltage or other system voltage, and can generate reset signal or set flag.

SVS module has only one 8-bit register, which is very convenient to use. Register svsctl:

The high four bit vldx is used to set the threshold of monitoring power supply voltage, turn off SVS or select to monitor external input voltage. The specific meaning is as follows:

0000 SVS is off 0001 1.9 V to detect whether the avcc is lower than 1.9 v. the following is similar to 0010 2.1 V 0011 2.2 V 0100 2.3 V 0101 2.4 V 0110 2.5 V 0111 2.65 V 1000 2.8 V 1001 2.9 V 1010 3.05 1011 3.2 V 1100 3.35 V 1101 3.5 V 1110 3.7 V 1111 to detect whether the voltage input by the svsin pin is lower than 1.2 V.

When the high four bits are 0, the SVS module is closed; 1-14 are 14 threshold voltages for power supply voltage monitoring; when 15, the external voltage is monitored, and the threshold voltage is 1.2V.

When the PORON bit sets whether the starting voltage is lower than the threshold, the MCU resets: 1 reset 0 set flag svsfg

The svson bit is different from the on bit of other modules. The svson bit only indicates whether the current SVS module is open or not, not used to switch the module.

Svsop bit, this is to set the output value of SVS internal comparator: 0 output low level, 1 output high level.

Svsfg bit and flag bit indicate whether low voltage is detected or not. Only when PORON is 0, low voltage post-1 will appear effectively; instead, it will not be reset automatically and must be reset by software.

In addition, the SVS module is worth mentioning: the SVS threshold voltage has been set back to the differential band: the level of each SVS has lagged avcc, close to the critical value, in order to reduce the sensitivity of small power supply voltage changes. The operation of SVS and the interoperability of SVS / power down are shown in the figure

As shown in the figure: in order to prevent SVS from being too sensitive when the voltage changes near the threshold, there is a backlash band near each threshold. In this way, the SVS module can be used better.

Program implementation:

The program is mainly to set and detect the register svsctl of SVS module. First, set the SVS function

Void svssetup (char voltagelevel, char reset) {svsctl = voltagelevel < 4; ='If (voltagelevel ='0x15) ='external input ='open corresponding function port = '{='p6sel' ='bit7; 'no need. When svsin is used, it will automatically detect from this foot ='} * / ='If (reset '= > < = 1) =' {='svsctl '='reset' > = > < 3; =} '= >

Voltagelevel: this parameter has the same meaning as the vldx of the upper four bits of the register svsctl. The program just moves it to the upper four bits and assigns it to the register svsctl. The reset parameter corresponds to the PORON bit, which is also assigned directly to the corresponding bit to complete the setting.

Check whether the voltage is lower than the threshold

char SvsFlg(){    return (SVSCTL&SVSFG);}

This function is simpler, just returns the value of the flag bit svsfg, so that the user can judge whether there is a situation below the threshold.

Flag bit clear:

/*****************************************************************************Name: clearsvs * function: low flag of power supply voltage monitor * entry parameter: Sync: synchronization 1: blocking operation until the function voltage returns to normal 0: no blocking, Clear to return * exit parameter: none * Note: if the incoming parameter is 0 and not blocked, if the voltage does not return to the normal range, the flag will be reset immediately by the MCU (1) * if (! Sync) {svsctl & = ~ svsfg; return; }While (svsctl & svsfg) svsctl & = ~ svsfg; / / clear the flag until the voltage is normal}

Since the flag bit of svsfg will not be cleared automatically after processing, it must be cleared by software. This function works in two ways: synchronous blocking and waiting until the voltage returns to normal and clearing.

The program is relatively simple, but it can complete the function of SVS. The following describes how to use this library.

Use example:

The way to use the library is the same as before: the SVS. C file is added to the project, and the SVS. H file is added to the source file.

The main contents of main. C are as follows:

#include//430 register header file? Include#Include "LCD12864. H" # include "SVS. H" / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * When the data of LCD Plus 1 is not reset, the output voltage is too low by turning down one at a time. ****************************************************************************/Void main() {/ / stop watchdog timer to prevent time out reset wdtctl = wdtpw + wdthold; clkinit(); lcdinit(); / * / / = = = = = = reset test when voltage is too low = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =__ No_ Init char FF; / / reset the uninitialized svssetup (0x0a, 1); / / when the power supply voltage is detected to be 3.05v and lower than 3.05v, the MCU resets FF + +; / / add 1 printf (% D, FF) / / when the voltage is lowered (< 3.05v) and then raised, the variable will be increased by 1 * / = "svssetup (0x0a, 0); =" measure the power supply voltage = "3.05v =" when the voltage is lower than 3.05v, the MCU = " If not reset, the p6.7 voltage will be monitored and detected to see if it is lower than 1.2V, while (1) = '{if (svsflg()) =' printf ';' svsfg bit must be reset by software. If the voltage does not return to above 3.05, the value of 'svsfg bit' will be set to 1 'clearsvs (1) by MCU immediately; ="Clear flag =" until the normal voltage is restored = "} = > 3.05v) and then increase, the display variable will be increased by 1 >

This program uses 12864 LCD to display the situation of low voltage: reset, set a__ No_ Init variable, each reset plus 1, you can see that after the voltage is reduced, the display number is increased by 1. The underlying driver of 12864 and printf function transplantation are used here, which are slightly changed than before. These have been explained in detail in the comments, and I won’t go into details here.

Leave a Reply

Your email address will not be published. Required fields are marked *