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.
This short guide is about starting first project with IAR Embedded Workbench for Atmel AVR. IDE is not free, bet there is free KickStart edition with 4KB code limit.
This meter gives the best results at 0 – 1000 Hz range. It works by measuring square wave total and high period duration using 16 bit hardware counter.
As you may know frequency = 1/Period and Duty Cycle = High period duration/total period duration.
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)