Reference no: EM133751239 , Length: word count:2000
Advanced Embedded Systems
Task: Writing specialised functions for the Timer registers on the SAMD21G18A MCU on the Arduino Nano 33 IOT
Introduction
In event driven embedded programming, timing is a critical factor. Most of us using Arduino would use the delay(ms) function which takes arguments as number of milliseconds. The delay() function directly access the timers through the timer setup and timer control registers. What if we need a higher resolution in timing, for example 10.5 milliseconds? Can this be achieved? In this task, we look deeper at exactly how timers are configured to achieve the required functions.
Task:
In this task, you will write your own C-functions to directly access, configure and control the timer registers of the SAMD21G18A MCU. You will need to refer to the SAMD21G18A MCU datasheet. This task builds on Task 2.0, so you may want to complete that task first before attempting this one. The task is as follows:
Develop and write a class in C called TIMER_DEAKIN which contains the following methods:
config_timer(xxx) to configure and separately use 16-bit timers. The input arguments will be the timer number, the starting count value, the ending count value and the timer resolution in 0.1ms ticks. The method returns true if the configuration is successful and false otherwise. Ensure you select the appropriate data types for the input arguments, giving reasons why.
For each timer, write a method to return the value of the timer counter. For example, for TC0, you can name your method getTC0_count() to return the timer counter value. Consider what the return value should be. How many timers does the MCU SAMD21G18A have for the Arduino Nano 33 IoT to use?
Now write your own method called wait() that takes as its argument the period in terms of 0.1 ms. Note this is different to delay(ms) in Arduino C. You will need to configure the appropriate timer to use without interfering with the existing timers used for the Nano.
Modify the Arduino program to blink an LED using your developed class TIMER_DEAKIN and demonstrates that it works. This program can only use methods developed in GPIO_DEAKIN and TIMER _DEAKIN classes. The new methods developed by you in this task must directly write to the relevant timer registers and not use the default Arduino timer functions such as delay().