<var id="fnfpo"><source id="fnfpo"></source></var>
<rp id="fnfpo"></rp>

<em id="fnfpo"><object id="fnfpo"><input id="fnfpo"></input></object></em>
<em id="fnfpo"><acronym id="fnfpo"></acronym></em>
  • <th id="fnfpo"><track id="fnfpo"></track></th>
  • <progress id="fnfpo"><track id="fnfpo"></track></progress>
  • <tbody id="fnfpo"><pre id="fnfpo"></pre></tbody>

  • x
    x

    如何使用STM32的PVD對電源的電壓進行監控

    發布時間:2009-11-25 17:28    發布者:STM32
    關鍵詞: PVD , 電壓 , 電源
    用戶在使用STM32時,可以利用其內部的PVD對VDD的電壓進行監控,通過電源控制寄存器(PWR_CR)中的PLS[2:0]位來設定監控的電壓值。

    PLS[2:0]位用于選擇PVD監控電源的電壓閥值:

    000:2.2V
    001:2.3V
    010:2.4V
    011:2.5V
    100:2.6V
    101:2.7V
    110:2.8V
    111:2.9V

    在電源控制/狀態寄存器(PWR_CSR)中的PVDO標志用來表明VDD是高于還是低于PVD設定的電壓閥值。該事件連接到外部中斷的第16線,如果該中斷在外部中斷寄存器中被使能的,該事件就會產生中斷。當VDD下降到PVD閥值以下和(或)當VDD上升到PVD閥值之上時,根據外部中斷第16 線的上升/下降邊沿觸發設置,就會產生PVD中斷。這一特性可用于發現電壓出現異常時,執行緊急關閉任務。

    下面是用于測試PVD的代碼:

    主程序的代碼:

    /* Includes ------------------------------------------------------------------*/
    #include "stm32f10x_lib.h"
    /* Private typedef -----------------------------------------------------------*/
    typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
    /* Private define ------------------------------------------------------------*/
    /* Private macro -------------------------------------------------------------*/
    /* Private variables ---------------------------------------------------------*/
    ErrorStatus HSEStartUpStatus;
    /* Private function prototypes -----------------------------------------------*/
    void RCC_Configuration(void);
    void GPIO_Configuration(void);
    void EXTI_Configuration(void);
    void NVIC_Configuration(void);
    /* Private functions ---------------------------------------------------------*/
    STM32 中文應用文檔
    /*****************************************************************************
    * Function Name : main
    * Description : Main program
    * Input : None
    * Output : None
    * Return : None
    ******************************************************************************/
    int main(void)
    {
    RCC_Configuration(); /* System Clocks Configuration */
    GPIO_Configuration(); /* Configure the GPIO ports */
    NVIC_Configuration(); /* NVIC configuration */
    EXTI_Configuration();
    PWR_PVDLevelConfig(PWR_PVDLevel_2V8);
    PWR_PVDCmd(ENABLE);
    while(1) {}
    }
    /*******************************************************************
    * Function Name : RCC_Configuration
    * Description : Configures the different system clocks.
    * Input : None
    * Output : None
    * Return : None
    ********************************************************************/
    void RCC_Configuration(void)
    {
    RCC_DeInit(); // RCC system reset(for debug purpose)
    RCC_HSEConfig(RCC_HSE_ON); // Enable HSE
    HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready
    if(HSEStartUpStatus == SUCCESS) {
    RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
    RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
    RCC_PCLK1Config(RCC_HCLK_Div1); // PCLK1 = HCLK/2
    FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch Buffer
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHz
    RCC_PLLCmd(ENABLE); // Enable PLL
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} // Wait till PLL is ready
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
    while(RCC_GetSYSCLKSource() != 0x08) {} // Wait till PLL is used as system clock source
    }
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    }
    STM32 中文應用文檔
    /****************************************************************
    * Function Name : GPIO_Configuration
    * Description : Configures the different GPIO ports.
    * Input : None
    * Output : None
    * Return : None
    ****************************************************************/
    void GPIO_Configuration(void)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
    GPIO_Init(GPIOB, &GPIO_InitStructure); //GPIO B
    }
    /*******************************************************************
    * Function Name : EXTI_Configuration
    * Description : Configures .
    * Input : None
    * Output : None
    * Return : None
    ********************************************************************/
    void EXTI_Configuration(void)
    {
    EXTI_InitTypeDef EXTI_InitStructure;
    EXTI_DeInit();
    EXTI_StructInit(&EXTI_InitStructure);
    EXTI_InitStructure.EXTI_Line = EXTI_Line16;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure); // Configure EXTI Line16 to generate an interrupt
    }
    /***************************************************************************
    * Function Name : NVIC_Configuration
    * Description : Configures Vector Table base location.
    * Input : None
    * Output : None
    * Return : None
    **************************************************************************/
    void NVIC_Configuration(void)
    {
    NVIC_InitTypeDef NVIC_InitStructure;
    #ifdef VECT_TAB_RAM
    /* Set the Vector Table base location at 0x20000000 */
    NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
    #else /* VECT_TAB_FLASH */
    /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    #endif
    STM32 中文應用文檔
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); // Configure one bit for preemption priority
    NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure); // Enable the PVD Interrupt
    }
    中斷程序:
    /**************************************************************************
    * Function Name : PVD_IRQHandler
    * Description : This function handles PVD interrupt request.
    * Input : None
    * Output : None
    * Return : None
    ***************************************************************************/
    void PVD_IRQHandler(void)
    {
    if (PWR_GetFlagStatus(PWR_FLAG_PVDO))
    GPIO_WriteBit(GPIOB, 1 << 5, Bit_SET);
    else
    GPIO_WriteBit(GPIOB, 1 << 5, Bit_RESET);
    }

    注:在void EXTI_Configuration(void)中,對于EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; 中的初始化值,根據你的需要進行修改,具體細節如下:

    EXTI_Trigger_Rising --- 表示電壓從高電壓下降到低于設定的電壓閥值產生中斷;
    EXTI_Trigger_Falling --- 表示電壓從低電壓上升到高于設定的電壓閥值產生中斷;
    EXTI_Trigger_Rising_Falling --- 表示電壓從高電壓下降到低于設定的電壓閥值、或從低電壓上升到高于設定的電壓閥值產生中斷。

    本文PDF格式: 1.pdf (66.5 KB)

    最初發表日期:2008-7-16
    本文地址:http://www.portaltwn.com/thread-5765-1-1.html     【打印本頁】

    本站部分文章為轉載或網友發布,目的在于傳遞和分享信息,并不代表本網贊同其觀點和對其真實性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問題,我們將根據著作權人的要求,第一時間更正或刪除。
    您需要登錄后才可以發表評論 登錄 | 立即注冊

    廠商推薦

    • Microchip視頻專區
    • 更佳設計的解決方案——Microchip模擬開發生態系統
    • 我們是Microchip
    • 想要避免發生災難,就用MPLAB SiC電源仿真器!
    • 你仿真過嗎?使用免費的MPLAB Mindi模擬仿真器降低設計風險
    • 貿澤電子(Mouser)專區

    相關在線工具

    相關視頻

    關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
    電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
    快速回復 返回頂部 返回列表
    精品一区二区三区自拍图片区_国产成人亚洲精品_亚洲Va欧美va国产综合888_久久亚洲国产精品五月天婷