MSP430 library SVS (Power Supply Voltage Monitor) Module

Source: Internet
Author: User

Power supply voltage monitoring is also a frequently used module for single-chip microcomputer. When stable industrial products are required, the power supply voltage is often monitored to ensure that the single chip microcomputer system works in a normal environment or range. Msp430f16x provides a ready-made supply voltage monitor module SVS, which is convenient for detecting the power supply voltage or external voltage. It can be set to reset or set the flag when the voltage is too low. BenProgramThat is, the library used to complete the settings of SVS (not available in msp430f14x ).

  1. Hardware introduction:

    The SVS module of MSP430 can conveniently 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 when the power supply voltage or external voltage falls below the selected voltage level, or generate por reset.

    The SVS module has the following features: it can monitor avcc voltage, can generate reset signal, can set SVS comparator output signal, and can be locked or accessed by user programs; there are 14 Available voltage thresholds; external input voltage can be monitored. The SVS module can easily monitor the power supply voltage or other system voltage, and generate reset signals or flags.

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

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

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

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

    Poron bit set whether the start voltage is lower than the threshold, single chip microcomputer Reset: 1 reset 0 set flag svsfg

    Svson bit. This is not the same as the on bit of other modules. The svson bit only indicates whether the current SVS module is enabled, rather than used to switch the module.

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

    Svsfg, flag indicates whether the low voltage is detected. Only when poron is 0, the low voltage rear 1 is effective. If it is changed, it will not be automatically cleared and software must be cleared.

    In addition, the SVS module is worth mentioning that the SVS threshold voltage has been set with a return band: The level of each SVS has lagged behind avcc, close to the critical value, to reduce the sensitivity of small power supply voltage changes. SVS operations and SVS/power-down interoperability

    To prevent voltage changes near the threshold, SVS is too sensitive and there is a return band near each threshold. In this way, the SVS module is easier to use.

  2. Program Implementation:

    The program mainly sets and detects the svsctl register of the SVS module. First, set the SVS function:

     
    VoidSvssetup (CharVoltagelevel,CharReset) {svsctl = voltagelevel <4;/* If (voltagelevel = 0x15) // open the corresponding function port {p6sel | = bit7; // No. When svsin is used, automatically detect this script }*/If(Reset <= 1) {svsctl | = reset <3 ;}}

    Voltagelevel: this parameter is exactly the same as the four-bit vldx in the register svsctl. The program only moves it to the four-bit high and assigns it to the Register svsctl. The reset parameter corresponds to the poron bit, it is also directly assigned to the corresponding bit to complete the settings.

    Check whether there is any lower than the threshold voltage:

     
    CharSvsflg (){Return(Svsctl & svsfg );}

    This function is simpler. It only returns the svsfg value of the flag, so that the user can determine whether the value is lower than the threshold.

    Flags are cleared:

    /*************************************** * *********************************** Name: clearsvs * Function Energy: Power Supply Voltage Monitor Low sign * entry parameter: Sync: synchronization 1: blocking operation until the function voltage returns to normal 0: no blocking, clear returns * outlet parameter: none * Description: If the input parameter is 0 and the voltage is not restored to the normal range, it indicates that the voltage will be reset by the microcontroller immediately (1) **************************************** ************************************/VoidClearsvs (CharSync ){If(! Sync) {svsctl & = ~ Svsfg;Return;}While(Svsctl & svsfg) svsctl & = ~ Svsfg;// Clear the flag until the voltage is normal}

    Because the svsfg flag is not automatically cleared after processing, the software must be cleared. This function works in two ways. synchronous blocking waits until the voltage returns normally.

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

  3. Example:

    Use the library in the same way as before: add the SVS. c file to the project, and add the file containing SVS. H to the source file.

    Main. C:

     # Include  <Rjx16x. h>  // Register header file 430  # Include  <Stdio. h>  # Include  "Lcd12864.h"  # Include  "SVS. H"  /*************************************** * *********************************** Name: main main program * function: Set the serial port, output information, read data from the computer keyboard from the serial port, test the serial port sending and receiving * entry parameter: none * exit parameter: none * description: during the reset test, each time the voltage is lowered, and then the data displayed in the normal LCD is adjusted. When the value of 1 is not reset, each time the output voltage is lowered, the output voltage is too low. **************************************** ************************************/ Void Main (){ // Stop watchdog timer to prevent time out Reset Wdtctl = wdtpw + wdthold; clkinit (); lcdinit (); /* // ========= Reset test when the voltage is too low ===============_ _ no_init char ff; // reset does not initialize svssetup (0x0a, 1); // when detecting that the power supply voltage is less than 3.05v, the MCU resets FF ++; // This variable is reset with 1 printf ("% d", ff) each time; // the voltage is lowered (<3.05 V) and then increased. The variable will be added with 1 */ Svssetup (0x0a, 0 ); // When the power supply voltage is 3.05 V lower than 3.05v, the single chip microcomputer does not reset. // If 0x0a is changed to 0x0f, The p6.7 voltage monitoring check is less than 1.2 V  While (1 ){ If (Svsflg () printf ( "Low voltage" );// The svsfg bit must be cleared by software. If the voltage does not return to more than 3.05, The // bit value is immediately set to 1 by the microcontroller. Clearsvs (1 ); // Clear the flag until the normal voltage is restored }}

    This program uses 12864 liquid crystal to show the case of low voltage: reset, set a _ no_init variable, each reset plus 1, you can see that the voltage is lowered, the display number is added 1. the voltage is too low. Here we use the 12864 underlying driver and printf function porting, which are slightly different from the previous ones. The descriptions in the annotations are very detailed. For more information about liquid crystal and printf, see <3> 12864 LCD library and MSP430 library <4> printf and scanf function porting.

The SVS module is here. If you have any questions, please click it.

Attachment: Library

Author:Give me a drink

Source: http://Engin.cnblogs.com/

The copyright of this article is shared by the author and the blog Park. You are welcome to repost it. repost the text and indicate the source. Thank you.

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.