Timer Library Documentation

ZPUino is a system-on-a-chip comprising one small CPU (ZPU 32-bit processor core), a few devices and it's meant to be implemented on a FPGA and mimic, the successfull Arduino platform. Hardware wise, ZPUino currently integrates two generic timers, which are able to generate PWM signals.

Main Goal: In this wiki page, we will focus only on the timer side. Right now, if you want to do configuration setup you have to write it manually within registers, which is beyond the skills of many end users. That's why a timer library is provided in C language to make abstraction level higher. So, this wiki page is considered as a simple guide to help using this library without referring to datasheet.


Getting Started

Timers and counters are so important hardware in almost all processors. As the name implies, timers can tell the time and count. They allow for some really cool things, like controlling the brightness of LED's, controlling the angle of servo shafts, receiving sensor data that transmit in PWM (Pulse With Modulation), making a timer (like on the stove) or just simply adding a timer variable to your project.

Quick Links:

To have more details about ZPUino timers, you can see the official project web site or Alvaro blog. Alvaro is the project owner who has developed the C library to configure ou timers:



Timer Specifications

According to the ZPUino 1.0 datasheet, we find the fllowing specifications:

  1. a 16-bit timer with prescalar and TSC
  2. a 24-bit timer with no prescalar nor TSC
  3. count-up and count-down mode
  4. 16-bit compare register
  5. clear on compare match support
  6. interrupt support
  7. output compare register to GPIO pin allowing PWM

TimerInstance_Class

This class is the base of any timer implementation, deriving from REGAccess Class. It provides low-level access to the timer configuration in hardware, so you should not use it directly. This class implementaion has one private attribute: m_inline, which refers to the interruption line number, and a set of public methods as following:


Timers_Class

This class is a higher implementation of the TimerInstance_Class class, deriving from BaseDevice class. It contains many private attributes, essentially you find m_timers array to save timer instances (2) and m_interTimer variable which refers to the active one. Since you are not concerned by the internal behaviour of this class, you should only understand the following public functions, so you can use them in your software:

Public functions

Example

LCD digital clock


Conclusion

I hope this wiki page helps expalain the use of timer library with PWM modes of ZPUino. Please let me know if you encounter any problem.


Author

Nassim TLILI
Embedded Software Engineer
LPI Linux Professional Certified
mail: nassim.enit@gmail.com

  

Share |