Cascading Timers to Create a Long Delay

cascade
Here is a demonstration program that runs on an Arduino which creates a 1 minute long delay by cascading timers. The procedure is outlined in Atmel Application Note AVR133.

I’ve set timer #1 up to toggle the OCR1A pin (D9) and wired that to the T0 pin (D4) which clocks timer #0. Then I put the arduino to sleep and wait for the timer #0 interrupt to wake it. The values I’m using should toggle the pin 13 LED at a 1 minute frequency.

A much longer delay is easily possible by increasing the counter values and the timer #1 prescaler. For example, with a 1024 prescale and maximum counter values, a delay of over 35 minutes is possible (with a 16MHz system clock).

Note: the reprogrammed timer 0 and 1 trashes the original arduino functions of these timers.

// AVR 133: Atmel Application Note Long Delay Generation Demo
// Blinks LED on a 1 minute period:
// T = 2/Fs x T1P x OCR1A x (256 - TCNT0)
// T = 2/16000000x256x7500x(256-6)
// T = 60 or 1 minute
//
// connect arduino D9 to D4: 
//  T0   = PD4 (Arduino D4 as input)
//  OC1A = PB1 (Arduino D9 as output)
#include <avr/sleep.h>
#include <avr/power.h>

void setup() {
  cli();
  
  //set pins
  DDRB |= (1<<PINB1) | (1<<PINB5); //set arduino D9 and D13 as outputs
  PORTB &= ~(1<<PINB1);            //set D9 low
  PORTD &= ~(1<<PIND4);            //set D4 low

  //timer #1 toggles OCR1A on TCNT1=0 in turn toggling T0
  TCCR1A = (1<<COM1A0); //TCCR1A toggle OC1A on compare match
  TCCR1B = 0;
  TCCR1C = 0;
  OCR1A = 7500;       //output compare register on division ratio of 7500
  TIMSK1 = 0;

  //timer #0 fires interrupt when TCNT0=0 waking arduino 
  TCCR0A = 0;
  TCCR0B = 0;
  TIMSK0 = (1<<TOIE0);  //enable timer0 interrupt
  
  sei();
}

void loop() {
  //toggle led
  PORTB ^= (1<<PINB5); //toggle led pin 

  //reset timers
  TCNT0 = 6;
  TCCR0B = (1<<CS00) | (1<<CS01) | (1<<CS02); //external source (t0) rising edge
  TCNT1 = 0UL;
  TCCR1B = (1<<WGM12) | (1<<CS12); //CTC mode 4 and 256 prescaler

  //sleep and power down setup
  set_sleep_mode(SLEEP_MODE_IDLE);
  sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer2_disable();
  power_twi_disable();
  sleep_mode();
  //go to sleep here
  sleep_disable();

  //wake upon timer #0 interrupt here
  power_all_enable();
 
  //stop timers
  TCCR1B = 0;
  TCCR0B = 0; 
}
Posted in Uncategorized | Tagged , , , , , , | 2 Comments

Hall Effect Sensor BoB

US5881

I made a tiny breakout board for a Melexis US5881 hall effect sensor. A HES detects whether a magnet is near, and is useful for non-contact/waterproof type switches, position sensors and rotary/shaft encoders.

US5881

Here is the circuit utilized on the BoB:

US5881

The BoB has been sent to OSHPark.com for fabrication. 3 copies cost me $1.40 (shipped). I find that unbelievable.

An US5881 HES is available from adafruit here.

Melexis datasheet is located here.

Posted in Uncategorized | Tagged , , , | Leave a comment

NavSpark and GPS Predictive Lap Timer

stopwatch
This cool little programmable (via a modified Arduino IDE) GNSS device should be capable of implementing all of the functionality needed for a predictive Lap Timer. There are models which integrate GPS/Beidou, GPS/GLONASS and GPS/Galileo. SkyTraq Technology Inc., a leading GNSS technology company, developed the device via an Indiegogo crowdfunding campaign. I have several on the way.

Navspark

NavSpark features:
100MHz 32bit RISC Processor with 16Kbyte I-Cache and 2Kbyte D-Cache
IEEE-754 Compliant Floating Point Unit
1MByte Flash Memory
212Kbyte SRAM
GPS Receiver
UART x 2
SPI x 2
I2C x 1
17 Digital I/O (shared with above functional pins)
1 Pulse Per Sec Timing Reference with +/-10nsec Accuracy
Customized Arduino IDE with GPS SDK Seamlessly Integrated

Posted in Uncategorized | Tagged , , , , | Leave a comment

Boardtrack Racer

boardtracker

Slightly off topic, however relative to using Eagle to design a PCB. I’ve built a gas powered bicycle. It uses a Chinese 2-stroke engine purchased off the internet for approximately $125. The kit includes everything needed to convert a basic bicycle into a motorized version. Here is my Beach Cruiser:

bike

I’ve made a few improvements to the package over time, the most recent being a high-power CDI/coil electronic ignition system. Cost of the CDI/coil package is about $20 each. This was the first time I used a potting compound to seal the board from the elements. The PCBs were made at OSHPark.com in a batch of 3 for approximately $14. Anyone interested in the files and list of materials can email me.

Schematic:
schematic
PCB:
board

Posted in Uncategorized | Tagged , | Leave a comment

New Project Under Wraps

wrapped package
I’ve been busy working on a new project. I am hesitant to publish any details yet. It has required making several PCBs in an iterative process, and I needed to learn SMD soldering. I will soon post about the lessons I learned. Here are a few photos:

ADXL-377 Eagle file:
adxl377bob

ADXL-377 Breakout Board:
adxl377bob

RXM418LR Breakout Board:
rxm418lr

xminilab SMD soldering:
xminilab

Secret Project:
HITsafe BoB

Posted in Uncategorized | Leave a comment

Great Cadsoft Eagle Starter Project Idea

starter
Here is a great starter project to try when attempting to learn Cadsoft Eagle. Make a simple breakout board for a SMD device.

For example, here I’m making a breakout for the SSOP-28 package with a .65mm pitch. This breakout will also accept SSOP-14, 16, 20 and 24 pin devices. I sent this design to OSPark for fabrication, and total cost for 3 PCBs, delivered was $7.80. To start out, you can easily copy a device from an existing library, or if you want to go all out, make a library part yourself.

Here is the SparkFun equivalent SSOP to DIP Adapter breakout board at $3.95 each. Adafruit sells a 3-pack double-sided breakout that will accept a SOIC-28 package on the bottom side here.

Here is my post about Cadsoft Eagle tutorials.

Posted in Uncategorized | Leave a comment

PCB Design Resources

A few good resources for PCB design and layout:

1. SparkFun According To Pete: PCB Layout video

2. David Jones (of EEVBlog fame) PCB Design Tutorial (pdf)

3. Electronics Design Checklist

Posted in Uncategorized | Leave a comment