After sorting out how works 16 bit hardware timer it is time for 4 digits countdown timer. Having 16 bit timer and 7 segments LED code from earlier only were remaining to write timer’s modes (run/setup) and button’s control code. After putting all code to one place there is countdown timer with properties below:
Maximum 99 minutes 59 seconds countdown interval
1 second resolution
Sound indication with buzzer for finished countdown
LED indicates running timer, or relay instead for powering external devices for some period of time
2 buttons to set timer and start/pause/reset.
This time without additional code quotation, please find some code explanation within code, so code bellow.
I have idea to build precise clock, and GPS module is here because GPS satellites has atomic clock on board. I have chosen particularly this module, because it was the cheapest, that I could find on internet, only 15 USD with free shipping. While new GPS module costs 60 USD, thought You could find completed GPS navigator for 70 USD.
Module has simple 5 wires connection. It’s powered from 5V, but can also work form 3.3V power supply. Data from/to device flows via well known RS-232 interface’s RX and TX data lines. Module can be directly connected to PC using RS-232 (com port), but is also needs 5V power source, USB works well. RS232 have the same data structure as UART, but voltage levels are different, so it can’t be connected directly to microcontroller, logic level converter MAX232 must be used.
Module use standard NMEA-0183 standard interface for data transmission. One reason it’s good, because module outputs data continuously without any request, so really it can be used only one RS232 data line.
Cold start (18 minutes until GPS fix)
To test bought GPS module I had connected it to my desktop PC RS232 port. It’s very easy to test. because seller send my with documentation and test software – GPS Diagnostics V1.05. It decrypts data in NMEA format and shows it in user friendly way.
18 minutes elapsed until I got location from module, at so called Cold start. Cold start means, that GPS module doesn’t have primary data about time, and location, so it is impossible to calculate which of 24 satellites are in module “view”. In this scenario module searches for signal of all 24 satellites, consequently it takes some time. Seller recommended to test device with clear view of sky, but I placed module near open window, so it is why 18 minutes 🙂
After 7 minutes I got data from 2 satellites, no location info still, but UTC date and time from satellite.
After 18 minutes location is found.
Here is module’s best result – 6 satellites, but still near open window.
Warm start (5-6 seconds)
Module saves date, time and location information in memory. Next time it is turned on it uses that information for faster GPS fix. With built in RTC (Real time clock) used time is current, not the same as was when module last time worked.
There is GPS module pinout instructions from seller:
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.