Introduction In this lab, we will learn

Slides:



Advertisements
Similar presentations
Chung-Ta King National Tsing Hua University
Advertisements

Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Introduction of Holtek HT-46 series MCU
68HC11 Polling and Interrupts
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
: Little Red Riding Hood ★★★☆☆ 題組: Contest Volumes Archive with Online Judge 題號: 11067: Little Red Riding Hood 解題者:陳明凱 解題日期: 2008 年 3 月 14 日 題意:
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
資料結構實習-一 參數傳遞.
Getting Started with a Cortex-M3 Board
Dr. Kimberly E. Newman Hybrid Embedded wk3 Fall 2009.
BLDC MOTOR SPEED CONTROL USING EMBEDDED PROCESSOR
Chung-Ta King National Tsing Hua University
The 8051 Microcontroller architecture
3-1 System peripherals & Bus Structure Memory map of the LPC2300 device is one contiguous 32-bit address range. However, the device itself is made up of.
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
Timers.
ECS642U Embedded Systems Digital I/O William Marsh.
Department of Electrical Engineering, National Taiwan Ocean University NuMicro MCU Learning Board SDK Installation 1/29/2015 Richard.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
LAB 12: Timer and Interrupt Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Interrupt 마이크로 프로세서 (Micro Processor) 2015년 2학기 충북대학교 전자공학과 박 찬식
1 The LPC1768 Architecture (with focus on Cortex-M3)
Introduction In this lab , we will learn
MQX GPIO.
3/6/2017 Richard Kuo Assistant Professor
Outline Introduction to NuMaker TRIO Programming environment setup
Outline Introduction to Arduino UNO Programming environment setup GPIO
Outline Analog to digital conversion (ADC) of NuMaker TRIO
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
Cortex-M0 MCU Clocks & Pins
Microcontrollers & GPIO
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Computer System Laboratory
Project Title EVM IN 8051 Under the Guidance of Submitted by.
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
Implementation of Embedded OS
Timer and Interrupts.
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
UNIT – Microcontroller.
Prof. Chung-Ta King Department of Computer Science
CS4101 Introduction to Embedded Systems Lab 9: NuMaker ADC and LCD
CS4101 嵌入式系統概論 General Purpose IO
Interrupts, Counter and Timers
16x2 LCD Module on DE2-115 Digital Circuit Lab TA: Po-Chen Wu.
Freescale ARM I/O Programming
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
The Arduino Microcontroller: Atmel AVR Atmega 328
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
Computer Organization
Wireless Embedded Systems
Wireless Embedded Systems
Computer System Overview
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
ECE 3567 Microcontrollers Lab
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 8: NuMaker TRIO Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan

Introduction In this lab, we will learn How to set up and use GPIO of NuMaker TRIO? How to use timer and interrupt in NuMaker TRIO? How to set up the programming environment for NuMaker TRIO?

NuMaker TRIO Based on Nuvoton Cortex®-M0 NANO102 MCU Cortex-M0: 32-bit ARMv6 RISC processor Run up to 32Mhz, 32KB Flash ROM, 8KB SRAM 

NANO102 MCU

Sources for Clock Controller 32768Hz external low-speed crystal oscillator (LXT) 4~ 24 MHz external high-speed crystal oscillator (HXT) 12/16 MHz internal high-speed RC oscillator (HIRC) 10 kHz internal low-speed RC oscillator (LIRC) Programmable PLL FOUT (PLL source can be selected from HXT or HIRC) //Define Clock source #define MCU_CLOCK_SOURCE #define MCU_CLOCK_SOURCE_HIRC // HXT, LXT, HIRC, LIRC #define MCU_CLOCK_SOURCE_LXT #define MCU_CLOCK_FREQUENCY 32000000 //Hz range 16MHZ~32MHZ

GPIO Set Mode GPIO set mode: GPIO_SetMode(PA, BIT12, GPIO_PMD_OUTPUT); Library/StdDriver/src/gpio.c GPIO set mode: GPIO_SetMode(PA, BIT12, GPIO_PMD_OUTPUT); GPIO port: NANO102 = PA, PB, PC, PD, PE, PF Pin mask = BIT0~15 Single or multiple pins of specified GPIO port I/O modes: GPIO_PMD_INPUT: input only mode GPIO_PMD_OUTPUT: push-pull output mode GPIO_PMD_OPEN_DRAIN: open-drain output mode To write to pin 12 of port PA: PA12 = 0; To read from pin 12 of port PA: if (PA12 !=0) { } * @param[in] gpio GPIO port. It could be \ref PA, \ref PB, \ref PC, \ref PD, \ref PE or \ref PF. * @param[in] u32PinMask The single or multiple pins of specified GPIO port. * @param[in] u32Mode Operation mode. \ref GPIO_PMD_INPUT, \ref GPIO_PMD_OUTPUT, \ref GPIO_PMD_OPEN_DRAIN * * @return None * @details This function is used to set specified GPIO operation mode.

Sample Code #include <stdio.h> #include "Nano1X2Series.h" #include "MCU_init.h" #include "SYS_init.h" void Init_RGBLED(void) { GPIO_SetMode(PB, BIT15, GPIO_PMD_OUTPUT); GPIO_SetMode(PA, BIT14, GPIO_PMD_OUTPUT); GPIO_SetMode(PD, BIT10, GPIO_PMD_OUTPUT); PB15=1; // red LED off PA14=1; // green LED off PD10=1; // blue LED off }

Sample Code int32_t main() { SYS_Init(); Init_RGBLED(); while(1) { PB15=0; // Red LED on CLK_SysTickDelay(200000); PB15=1; // Red LED off PA14=0; // Green LED on PA14=1; // Green LED off PD10=0; // Blue LED on PD10=1; // Blue LED off }

Outline GPIO of NuMaker TRIO Timer and interrupt in NuMaker TRIO Programming environment for NuMaker TRIO

Timer Four timers: TIMER0, TIMER1, TIMER2, TIMER3 Four operating modes: One-shot mode Periodic mode Output Toggle mode Continuous mode Each timer is equipped with an 8-bit pre-scale counter, a 24-bit up-counter, a 24-bit compare register and an interrupt request signal

Timer Operating Modes Example: Timer Compare Register (TCMPR) = 100 One-Shot Periodic/ Toggle TCMPR= timer compare register Continuous

Example Using Continuous Mode TMR_CMPR (timer compare register) TMR_DR (timing counter value) TMR_IS (timer interrupt status) Continuous mode 就是當timer數到TMR_CMPR的時候,會發生interrupt,但interrupt結束後,counter不會歸0,而是往上數直到overflow (2^24-1) 如這張圖,當TMR_DR數到TMR_CMPR ( 80 ) 的時候,會發生interrupt,並把TMR_IS設為 1, 在這個interrupt我們可以更改TMR_CMPR的值 (200),並把TMR_IS設為 0 ,這樣counter繼續數地的時候,到200又會發生一次interrupt。

MCU_init.h for Timer //Define MCU Interfaces #define MCU_INTERFACE_TMR1 #define TMR1_CLOCK_SOURCE_HIRC // HXT, LXT, LIRC, EXT, HCLK #define TMR1_CLOCK_DIVIDER 1 #define TMR1_OPERATING_MODE TIMER_PERIODIC_MODE // ONESHOT, PERIODIC, TOGGLE, CONTINUOUS #define TMR1_OPERATING_FREQ 100 //Hz

Interrupt Controller Nested Vectored Interrupt Controller (NVIC) Support 32 (IRQ[31:0]) discrete interrupts with 4 levels of priority When an interrupt is accepted, the starting address of the interrupt service routine (ISR) is fetched from a vector table in memory While the starting address is fetched, NVIC will also automatically save processor state to the stack At the end of the ISR, the NVIC will restore the saved registers from stack and resume the normal execution

System Interrupt Map

NVIC Interrupt Variable

Interrupt Handler Function Name

Interrupt Sample Code #include <stdio.h> #include "Nano1X2Series.h" #include "MCU_init.h" #include "SYS_init.h" volatile uint32_t timer_count =0; void Init_Timer1(void) { TIMER_Open(TIMER1,TMR1_OPERATING_MODE,TMR1_OPERATING_FREQ); TIMER_EnableInt(TIMER1); //enable timer interrupt NVIC_EnableIRQ(TMR1_IRQn); TIMER_Start(TIMER1); } int32_t main() { SYS_Init(); Init_Timer1(); while(1) { } 它有指定發生interrupt的時候要去哪個 handler 的 function name,除了enable timer本身的interrupt,同時也要enable在NVIC裡對應位置的interrupt 

Interrupt Sample Code void TMR1_IRQHandler(void) { timer_count++; printf("Timer1 = %d, %d\n", timer_count,TIMER1->CMPR); TIMER_ClearIntFlag(TIMER1); // clear timer interrupt flag }

Outline GPIO of NuMaker TRIO Timer and interrupt in NuMaker TRIO Programming environment for NuMaker TRIO

Software Development Kit (SDK) ARM Keil Microcontroller Development Kit (MDK) IDE, C/C++ compiler, debugger for ARM Cortex-M https://www.keil.com/demo/eval/arm.htm Register and download MDK517.exe NuLink Driver Nu-Link_Keil_Driver_V1.30.6491.zip Driver to link PC to NuMaker TRIO board through USB Board Support Package (BSP): MCU device driver and sample code Nano102_BSPv3.02_EDU

NANO102 BSP

SampleCode Folder

NuMaker TRIO Folder Use Smpl_Debug as the template

Smpl_Debug Folder

Keil Folder Double click on .uvproj file to open a Keil project

Keil MCU Development Environment

Keil MDK Configuration

Build and Execute 1. Build your project

Build and Execute 2. Change to debug mode 3. Run your project

Debug Session

Lab Basic 1: Flash both red and green LEDs at 1 Hz. The red LED should be on for 0.7 sec and off for 0.3 sec, which is controlled by polling TIMER1 sourced by HIRC. The green LED should be on for 0.3 sec and off for 0.7 sec, which is controlled by polling TIMER0 sourced by LIRC, the divider of TIMER0 should be 2. Hint: TIMER_Open() will start counting compare register (TIMERX->CMPR) according to TMRX_OPERATING_FREQ in MCU_init.h (X=0,1,2,3). You can trace the function or print the variable to find the relationship between TMR1_OPERATING_FREQ and TIMERX->CMPR. Use TIMERX->CMPR to change the value of compare register.

Lab Basic 2: The traffic light will change to the green light when there is an ambulance passing. Let the blue LED represent the yellow traffic light, and the buzzer indicates the passing of an ambulance. Normally the red LED is on for 3 sec, then the blue LED is on for 2 sec, then the green LED is on for 4 sec, and repeat. The buzzer will be turned on for 4 sec at 2 Hz (0.5 sec on and 0.5 sec off). The starting time is set randomly between 6 and 15 sec. During the 4 sec that the buzzer sounds, the traffic light will be turned to the green LED. After the 4 sec, the traffic light returns to normal.