Tag Archives: interrupt

Arduino and ultra sonic range measurement module or how to measure the pulse time with a hardware timer and an interrupt

SEN136B5B is a Ultra Sonic range measurement from SeedStudio. It can measure the distance by sending a 40k Hz ultra sound impulse via the transmitter  and calculating time needed for echo to reach receiver. Detecting range: 3cm-4m. More information about device.

In the description of module is mentioned that it is compatible with Arduino library, but I decided to write program without using PulseIn command.

Continue reading

Examples of using Arduino/Atmega 16 bit hardware timer for digital clock

Arduino Mega with Atmega 1280 has four 16 bit timers, that could be used for various purposes, like time/frequency measurement, control with precise timing, PWM generation. Today I hope to explain how to use timer for clocks, timers (countdown) and other things, where You need µCPU to perform some tasks after precise period of time. I’ll give You two examples:

  • Pseudo 1 second timer
  • Real 1 second timer

How counter works? It is simple independent  16 bit accumulator, which value increases by 1 at clock cycle. 16 bit means that maximum counter’s value is 65536. When this value is reached counter starts counting from 0 again and gives hardware interrupt. Counter value could be changed any time. This is normal counter mode, Atmega 1280 offers total 14 operating modes.

Pseudo 1 second timer (1.048576 s)

Continue reading