發表文章

nuvoton - M451 Window Watchdog Timer

圖片
Window Watchdog Timer 特性 6 bits 下數計數器和比較器 16 selections window watchdog timer 預除器 Only one time to set windows watchdog timer controller after chip power-on or reset. Watchdog Timer 和 Window Watchdog Timer share a single IRQ handler 支援 window watchdog timer interrupt 支援 window watchdog timer reset Window Watchdog Timer Clock Source HCLK0 / 2048 LIRC (10 KHz) LXT (32.768 KHz) Window Watchdog Timer Block Diagram 11-bit prescale controlled PSCSEL (WWDT_CTL[11:8]) 當 CNTDAT = CMPDAT,就會產生 WWDT interrupt。而且當  CNTDAT <= CMPDAT時,設定 WWDT_RLDCNT = 0x5AA5,CNTDAT 就會重新載入 0x3F. 當  CNTDAT 繼續下數到 0 時,會產生 MCU reset。  當  CNTDAT > CMPDAT, 設定 WWDT_RLDCNT = 0x5AA5,就會產生 MCU 的 reset。 Window Watchdog Timer Function WWDT Counting WWDTEN (WWDT_CTL[0]) = 1, WWDT down counter from 0x3F to 0x00. WWDT_CTL written once after chip is powered on or reset. WWDTEN (WWDT_CTL[0]) enabled WWDT counter can't disable Counter Prescale Period (PSCSEL) can't change Window Compare V...

nuvoton - M451 Watchdog Timer

圖片
Watchdog Timer 特性 18 bits 上數的計數器 8 selections of timeout interval 2^(4 - 18) 4 selections of Watchdog reset delay period 3 / 18 / 130 / 1026 * TWDT  支援 watchdog timer interrupt 支援 watchdog timer reset 支援 watchdog wake-up Watchdog Timer Clock Source LXT (32.768 KHz) PCLK0 / 2048 LIRC (10 KHz) Watchdog Timer Block Diagram WDT Time-out interrupt WDTEN(WDT_CTL[7]) = 0, enable WDT and start WDT counter. 8 Timeout  interval selected by TOUTSEL(WDT_CTL[10:8]). WDT time-out set IF(WDT_CTL[3]) = 1, occur the WDT time-out interrupt. WDT Wake-up Clock source selected to LIRC or LXT WKEN(WDT_CTL[4]) enable WDT time-out interrupt to wake-up  power-down system and WKF (WDT_CTL[5]) = 1   WDT Reset Delay Period and Reset System RSTF (WDT_CTL[2]) keep 1 after WDT time-out reset RSTCNT (WDT_CTL[0]) to reset 18-bit WDT RSTDSEL (WDT_ALTCTL[1:0]) select reset delay RSTEN (WDT_CTL[1]) enable WDT reset RSTF (WDT_CTL[2]) =1 when WDT reset delay tim...

nuvoton - M451 Timer

圖片
Timer 支援的功能有 4 個 32-bits timer 控制器( 24 bits 的計數器和 8 bits 預除器) 6 個時脈來源 支援由 power-down mode 喚醒 CPU 支援事件計數功能 支援外部事件觸發功能 支援 4 種工作模式 One-shot Periodic  Toggle  Continuous counting   Timer Clock Source HXT (High Speed External Clock Source) TMRxSEL = 000b 4 - 24MHz LXT (Low Speed External Clock Source) TMRxSEL = 001b 32.768 KHz PCLK TMRxSEL = 010b T0 - T3 TMRxSEL = 011b LIRC (Low Speed Internal Clock Source) TMRxSEL = 100b 10 KHz HIRC (High Speed Internal Clock Source) TMRxSEL = 101b 22.1184 MHz Timer Block Diagram 由方塊圖得知,以 32 bits 計數器(8 bits pre-scale and 24 bits counter) 為核心, 計數 internal clock , external clock, external Event 等,計數的結果放在 TCNT. 而 Capture 模組,使用於計數 clock 數來取得速度. Timer Function Mode 根據設定,Timer 可以分成四種工作模式如下表: Timer 的中斷 TIF (TIMERx_INSTS[0]) -  當 TIMERx_CNT[23:0] 計數到 TIMERx_CMPDAT[23:0] CAPIF (TIMERx_EINSTS[0]) - 當 Tx_EXT 接腳接收到變化而且 CAPEDGE (TIMERx_EXTCTL[2:1] 設為 1.  Timer 四種工作模式如下: Timer Co...

FPGA sample - 如何使用 UART loopback 驗證

圖片
在範例中,使用 Intel MAX 10 core board 上的 CP1202 , 把系統的 USB 資料轉成 UART 的資料, 再由 FPGA 的 RX 接收, 再由 TX 傳送給系統的 USB. 硬體方塊圖 在硬體方面,只需要把 intel MAX 10 core board 的 mini USB 連接到 Notebook 就完成了. 因為在 intel MAX 10 core board 內有 CP2102 是一個 USB COM 的晶片, 所以當 intel MAX 10 core board 連接到 notebook, 就會建立一個 COM. Notebook 就可以透過 COM 和 intel MAX 10 core board 溝通. FPGA 程式碼方塊圖 Notebook 由 Termite 應用程式輸入資料,經過 USB COM(CP2102) 傳送到 FPGA Rx 程式模組, 經過 40ns (2 clock) 除雜訊功能,開始接收資料, start 由高阻抗變成高電位, int 也同樣變成高電位.啟動 Rx Config 採樣模組,在採樣點(資料位元的中心點), bps 就會變成高電位, Rx 模組讀取資料放到 Rx data 陣列. 直到資料接收完整, start 變成低電位, int 也同時變成低電位. 當 int 變成高電位,Tx 模組經過 20ns (1 clock) 除雜訊功能,開始計數接收資料,直到資料接收完整,啟動 Tx Config 傳送定位模組, 在資料定位點(資料位元的結束點), bps 會變成高電位,Tx 模組傳送資料到 notebook. Rx/Tx Config 採樣模組 `define BPS_115200 `define CLK_PERIORD 20 // define periord is 20ns(50MHz) `define BPS_SET 1152 // define baudrate is 115200bps `define BPS_PARA (10_000_000/`CLK_PERIORD/`BPS_SET) // bit width count = 1/115200/20(ns) // = 1...

FPGA sample - 如何使用七段顯示器

圖片
在範例中,會使用一個 12 位元計數器,每一秒會加一,再把計數器的值使用七段顯示器,把它顯示出來. 整個範例的方塊圖如下: 範例方塊可以分成: 1 second timer : 使用一個 50_000_000 的計數器, 因為輸入時脈為 50MHz, 計數到 50_000_000 就剛好 1 second. 12 bits counter : 每一秒將計數器加一. 7 segment led : 把 12 bits counter 的值, 轉成七段顯示器的控制碼. 7 bits counter : 用來選擇那一個七段顯示器顯示 12 bits counter 的值. 使用視覺暫留的原理,讓數值看起來是一起顯示的. 1 second timer 的程式碼 : reg[31:0] T1secTimer; // value of 1 second timer //----------------------------------------------------------- // function : 1 sec timer // input : clk (clock) 50MHz // : rst_n (reset) // output : none //----------------------------------------------------------- always @ (posedge clk or negedge rst_n) if(!rst_n) T1secTimer <= 31'd0; // reset state else if(T1secTimer >= 31'd50_000_000) T1secTimer <= 31'd0; // 1 second timer timeout else T1secTimer <= T1secTimer+1'b1; wire timer_1s = (T1secTimer == 31'd50_000_000); 12 ...

nuvoton - M451 Flash Memory Controller

圖片
M451 單晶片內部的 Flash 記憶體包含 40-256 KB APROM (Application ROM) 用來儲存應用程式的機器碼和應用程式相關的資料, 8 Bytes 的 User Configuration Block 儲存提供系統開機所需的參數和 4 KB 的 LDROM ( Loader ROM) User boot loader 初始化單晶片進入Flash 更新模式, 支援 ISP  (In System Programming)   和  IAP  (In Application Programming) . Flash 記憶體的特性 : Flash page erase size 為 2KB Flash programming 支援 32 bits/64 bits multi-word Flash verification 支援 Fast verification 計算 checksum Flash 增加存取的效率來減少功率損耗 Boot loader 支援 ISP  M451 使用 FMC (Flash Memory Controller) 來存取內部 Flash, 經由 AHB 連結到單晶片處理器, 4 KB cache memory 加快記憶體儲存速度, 16 KB boot loader 初始化單晶片進入Flash 更新模式, 支援 ISP 和 IAP . FMC 的方塊圖如下: Flash 記憶體的配置如下: APROM : 位於 0000_0000 到 0003_FFFF, 程式碼區塊和資料區塊是可以調整的, 由 DFBA (CONFIG1[19:0]) 區分資料和程式碼區塊. 其中 0000_0000 到 0000_01FF 為中斷向量服務程式. LDROM : 位於 0010_0000 到 0010_0FFF SPROM : 位於 0020_0000 到 0020_07FF (Security Protection ROM) User Configuration : 位於 0030_0000 到 0030_0003 (CONFIG[1:0]) Boot Loader : 位於 0080_0000 到 00...

Atmel Tiny88 16-bit Timer

圖片
Introduction 計時器是一個簡單的計數器 ,它的優點是系統程式在執行時,也不會影響到它的準確度。當然要有準確的系統時脈,才能讓計時器的時間是準確的。AVR 會有兩種計時器,分別為 8-bit 計時器和 16-bit 的計時器,這篇文章僅介紹 16-bit 計時器。 16-bit 計時器的特性: 16 位元的設計 兩個計數值比較單位的獨立輸出 兩個資料緩衝區給輸出比較暫存器 一個輸入取樣單位 輸入取樣單位有消除雜訊功能 比較暫存器達標後自動清除(自動重新載入) 無鋸齒,正確相位脈波寬度調整器(PWM) 多種週期的脈波調整器 頻率產生器 外部事件計數器 四個獨立的中斷向量,分別為 TOV1 / OCF1A / OCF1B / ICF1 16位元計時器的方塊圖 相關的暫存器說明 Timer/Counter 1 (TCNT1) - 計數器/計時器 #1 Output Compare Register (OCR1 A/B) - 比較器暫存器 #1 A/B 輸出,計數值和目標值相同時輸出。 Input Capture Register (ICR1) - 取樣暫存器 Timer Interrupt Flag Register (TIFR1) -  紀錄中斷旗標暫存器 Interrupt Mask Register (TIMSK1) - 中斷的開關 Timer/Counter Clock Source Timer/Counter 的時脈來源 - 外部的時脈產生器 內部的 System Clock - 內部的 System Clock 可以設定經除頻器後再送到 Timer/Counter 模組。由暫存器 Timer/Counter Control Register B(TCCR1B) 的 Clock Select (CS1[2:0]) 來決定時脈的來源。 Counter Unit Timer/Counter 是一個雙向(可以上數/下數)計數器,其方塊圖如下: 方塊圖中訊號的說明 - CLK Tn - Timer/Counter 時脈輸入 Count - 計數加/減 1 ...