• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
:::


Browsing this Thread:   1 Anonymous Users






Re: pic32mk的HLVD功能
#3
初級會員
初級會員


查看用戶資訊
感謝KevinLu的回覆, 以下是我的步驟

我先在我的初始化那邊加入以下程式
#ifndef __MPLAB_DEBUGGER_SIMULATOR
    
while ((HLVDCON _HLVDCON_BGVST_MASK) != (_HLVDCON_BGVST_MASK))
        ;
#endif
    
HLVDCONCLR _HLVDCON_VDIR_MASK;                   // Event occurs when voltage equals or falls below trip point
    
HLVDCONSET = (0b0110) << _HLVDCON_HLVDL_POSITION;  // 3.0V
    
HLVDCONCLR _HLVDCON_SIDL_MASK;
    
HLVDCONSET _HLVDCON_ON_MASK;


然後在interrupt.c那邊加入
void __attribute__((nomips16)) _nmi_handler(void) {
    
uint32_t getRNMICON RNMICON;
    
SYSKEY              0x00000000;
    
SYSKEY              0xAA996655;
    
SYSKEY              0x556699AA;

  ...

    if ((
getRNMICON _RNMICON_HLVD_MASK) == _RNMICON_HLVD_MASK) {
        
// Programmable High/Low-Voltage Detect
        
EEPROM_WordWrite(0x7000x87);
        
char          timestamp[16];
        
uart_buffer_t uartMessage = {};
        
formatString_Timestamp(timestamp);
        
sprintf(uartMessage.data,                      //
                
"rn%sRNMICON = 0x%08X;(%s:%d)rn",  //
                
timestamp,                             //
                
RNMICON,                               //
                
__FILE__,                              //
                
__LINE__);
        
uartMessage.len strlen(uartMessage.data);
        
UART_PushTxQueue(UART_6, &uartMessage);
        
RNMICONCLR _RNMICON_HLVD_MASK;
    }

    ...

    
SYSKEY 0x33333333;
    
asm volatile("eret");  // return from interrupt
}


我在我的按鈕那邊強制觸發HLVD
void Debounce_Tasks(void) {
    static 
bool flagChecked[DEBOUNCE_PIN_MAX];
    
bool        flagDebugMessage false;
    
getInputPin();

    for (
size_t pinIndex 0pinIndex DEBOUNCE_PIN_MAXpinIndex++) {
        if (
object[pinIndex].pinSetting.pullState == PULL_STATE_NONE) {
            
// 設置浮接的輸入腳不偵測
            
if (flagChecked[pinIndex] == false) {
                
flagChecked[pinIndex] = true;
                
flagDebugMessage      true;
            }
            
Nop();
        } else {
            if (
object[pinIndex].pinSetting.input == object[pinIndex].pinTriggerCondition) {
                if (
object[pinIndex].pinState != PIN_STATE_PRESSED) {
                    if ((
object[pinIndex].timer[DEBOUNCE_TIMER_PRESS] + >= BOUNCE_TIME)) {
                        
object[pinIndex].pinState PIN_STATE_PRESSED;
                        if (
pinIndex == DEBOUNCE_PIN_SWITCH_2) {
#ifndef __MPLAB_DEBUGGER_SIMULATOR
                            
ramStart[0] = BTL_TRIGGER_PATTERN;
                            
ramStart[1] = BTL_TRIGGER_PATTERN;
                            
ramStart[2] = BTL_TRIGGER_PATTERN;
                            
ramStart[3] = BTL_TRIGGER_PATTERN;
                            while (
UART5_WriteIsBusy())
                                ;
                            
formatString_Timestamp(timestamp);
                            
sprintf(uartMessage.data,                    //
                                    
"rn%sEntering Bootloader...rn",  //
                                    
timestamp                            //
                            
);
                            
uartMessage.len strlen(uartMessage.data);
                            
UART5_Write(uartMessage.datauartMessage.len);
                            while (
UART5_TransmitComplete() != true)
                                ;
                            
SYS_RESET_SoftwareReset();
#endif
                        
}
                        if (
pinIndex == DEBOUNCE_PIN_SWITCH_3) {
#ifndef __MPLAB_DEBUGGER_SIMULATOR
                            
formatString_Timestamp(timestamp);
                            
sprintf(uartMessage.data,                              //
                                    
"rn%sRNMICONSET = _RNMICON_HLVD_MASK;rn",  //
                                    
timestamp                                      //
                            
);
                            
uartMessage.len strlen(uartMessage.data);
                            
UART_PushTxQueue(UART_6, &uartMessage);

                            
SYSKEY     0x00000000;
                            
SYSKEY     0xAA996655;
                            
SYSKEY     0x556699AA;
                            
RNMICONSET _RNMICON_HLVD_MASK;
                            
SYSKEY     0x33333333;
                            
formatString_Timestamp(timestamp);
                            
sprintf(uartMessage.data,                      //
                                    
"rn%sRNMICON = 0x%08X;(%s:%d)rn",  //
                                    
timestamp,                             //
                                    
RNMICON,                               //
                                    
__FILE__,                              //
                                    
__LINE__);
                            
uartMessage.len strlen(uartMessage.data);
                            
UART_PushTxQueue(UART_6, &uartMessage);
#endif
                        
}

                        
flagDebugMessage true;
                    } else {
                        
object[pinIndex].timer[DEBOUNCE_TIMER_PRESS]++;
                    }
                }
                
object[pinIndex].timer[DEBOUNCE_TIMER_RELEASE] = 0;
            } else {
                if (
object[pinIndex].pinState != PIN_STATE_RELEASED) {
                    if (
object[pinIndex].timer[DEBOUNCE_TIMER_RELEASE] + >= BOUNCE_TIME) {
                        
object[pinIndex].pinState PIN_STATE_RELEASED;
                        
flagDebugMessage          true;
                    } else {
                        
object[pinIndex].timer[DEBOUNCE_TIMER_RELEASE]++;
                    }
                }
                
object[pinIndex].timer[DEBOUNCE_TIMER_PRESS] = 0;
            }
        }
        if (
flagDebugMessage) {
            
flagDebugMessage false;
            
formatString_Debounce(object[pinIndex].pinStatepinIndex);
        }
    }
}


我進Debug看, 我始終沒有進入過NMI, 然後我就在while加入polling RNMICON
if ((RNMICON _RNMICON_HLVD_MASK) == _RNMICON_HLVD_MASK) {
            
// Programmable High/Low-Voltage Detect
            
SYSKEY 0x00000000;
            
SYSKEY 0xAA996655;
            
SYSKEY 0x556699AA;
            
formatString_Timestamp(timestamp);
            
sprintf(uartMessage.data,                      //
                    
"rn%sRNMICON = 0x%08X;(%s:%d)rn",  //
                    
timestamp,                             //
                    
RNMICON,                               //
                    
__FILE__,                              //
                    
__LINE__);
            
uartMessage.len strlen(uartMessage.data);
            
UART_PushTxQueue(UART_6, &uartMessage);

            
RNMICONCLR _RNMICON_HLVD_MASK;
            
SYSKEY     0x33333333;
        }


這樣我可以強制舉旗RNMICON->HLVD, 但無法舉旗HLVDCON->HLEVT, 我猜是HLVD沒有被開啟, 但也沒有PMD使它開啟

以上是我測試的方法, 但我都沒有辦法觸發HLVD與進入NMI.

發表於: 2022/11/4 16:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic32mk的HLVD功能
#2
管理員
管理員


查看用戶資訊
a16450 你好,PIC32MK的 HLVD Event 中斷旗標在 RNMICON 暫存器的 HLVD bit,如下圖:
縮圖


HLVD 可以有多種觸發狀態,建議在程式中加入修改所有需要的設定值,並確認每個設定值符合實際觸發需求,如下圖:
縮圖

縮圖

縮圖


最後在程式中根據 HLVD 手冊上的步驟設定和執行,需注意部分暫存器名稱和功能與手冊上有些不同,如下圖:
縮圖

Attach file:



jpg  RNMICON.jpg (316.80 KB)
123092_6362236032e54.jpg 754X1006 px

jpg  BLOCK.jpg (53.89 KB)
123092_6362237185779.jpg 757X620 px

jpg  HLVD-1.jpg (208.00 KB)
123092_636223b521e7f.jpg 749X900 px

jpg  HLVD-2.jpg (91.69 KB)
123092_636223cc33c03.jpg 747X454 px

jpg  HLVD.jpg (269.59 KB)
123092_636223e1cdf17.jpg 811X760 px

發表於: 2022/11/2 15:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


pic32mk的HLVD功能
#1
初級會員
初級會員


查看用戶資訊
使用的晶片是pic32mk_mcm系列, 根據datasheet中32.0 HIGH/LOW-VOLTAGE DETECT(HLVD)有提到參考"DS60001408"這份文件.
在Section 38. High/Low-Voltage Detect (HLVD)[DS60001408]中的38.3.1 HLVD Setup(page. 6)所提到的步驟,
"5. Clear the HLVD Interrupt Flag in the Interrupt Controller, which may have been set from a
previous interrupt. Refer to the “Interrupts” chapter in the specific device data sheet for
HLVD interrupt-related information."

我翻片datasheet找不到相關的中斷旗標、設置方式, 甚至手動設置RNMICONSET = _RNMICON_HLVD_MASK
也無法進入NMI、讓HLEVT舉旗.

請問是否有先進使用過HLVD, 可以指導、交流 謝謝

發表於: 2022/11/1 13:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------