Difference between revisions of "Frequency meter"

From ShawnReevesWiki
Jump to navigationJump to search
 
(15 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[File:Frequency meter 372.jpg|256px|thumb|right|A 5-digit frequency meter featuring an LCD display.]]
 
[[File:Frequency meter 372.jpg|256px|thumb|right|A 5-digit frequency meter featuring an LCD display.]]
 
*Connect 1 Hall effect switch to watch a magnet passing once per cycle.
 
*Connect 1 Hall effect switch to watch a magnet passing once per cycle.
 +
**Hall effect switch may be unipolar or omni-polar, but not bipolar. If unipolar, take care to place magnet correctly.
 +
**Switching time needs to be shorter than inverse of desired highest frequency.
 
*Include a display with at least 4 characters.
 
*Include a display with at least 4 characters.
 
*Include a power switch to save the battery, and/or a reset switch.
 
*Include a power switch to save the battery, and/or a reset switch.
Line 10: Line 12:
  
 
===Circuit===
 
===Circuit===
[[File:Frequency-meter-PICAXE-08M2.png|512px|thumb|right|Circuit diagram for a frequency meter featuring an LCD display.]]
+
[[File:Frequency-meter-Arduino-on-a-board.png|512px|thumb|right|Circuit diagram for a frequency meter featuring an LCD display.]]
For a detailed diagram, see [[File:Frequency meter-PICAXE-08M2.pdf]].
+
For a detailed, printable diagram, see [[File:Frequency-meter-Arduino-on-a-board.pdf]]. For a previous version using a much less precise PICAXE 08M2, see [[File:Frequency meter-PICAXE-08M2.pdf]].
  
 
===Components===
 
===Components===
 +
See [[#Datasheets]] for specific tips.
 
*Breadboard (~$5)
 
*Breadboard (~$5)
*Micro-controller. I use a PICAXE 08M2. ($3)
+
**Hall effect switch, unipolar or omni-polar, with quick output rise and fall times.
**Resonator circuit if necessary. Not available for PICAXE 08M2. (~$1)
+
*Micro-controller. I use an Atmel ATmega328. A previous version used a PICAXE 08M2. (both $3)
*Floating point math unit (~$10) optional
+
**Resonator circuit if necessary. The ATmega328 uses a 16MHz crystal and two ~20pf capacitors. (~$1)
 
*Display
 
*Display
 
**LCD Display, serial capable. I use Electronic Assembly's DOGM081 with SPI. ($10)
 
**LCD Display, serial capable. I use Electronic Assembly's DOGM081 with SPI. ($10)
 
**Alternatively, a TTL-to-USB or TTL-to-serial circuit for sharing data with computer ($18)
 
**Alternatively, a TTL-to-USB or TTL-to-serial circuit for sharing data with computer ($18)
 
*Hook-up wires ($2)
 
*Hook-up wires ($2)
*Power supply
+
*Power supply. Our LCD is expecting 4.7V to 5.3V.
**9V or a quartet of AAA with a 5V voltage regulator, capacitor(s), resistor(s), or
+
[[File:Voltage-regulator-circuit.png|256px|thumb|right|A typical 5V regulated circuit, with protective diode and output capacitor. The input voltage must be greater than the dropout voltage of the regulator plus the voltage of the diode plus the output voltage (see a data-sheet).]]
**120V AC to 5V DC adapter, or
+
**9V or a quartet of AAA with a 5V voltage regulator and capacitor(s), or
 +
**120V AC to 5V DC adapter—I find phone chargers at thrift stores for $1 each, or
 
**Three alkaline AAA or AA batteries, or
 
**Three alkaline AAA or AA batteries, or
**Four NiMH rechargeable batteries.
+
**Four NiMH rechargeable batteries, or
 +
**Three NiMH rechargeable batteries with a 5V voltage booster.
  
 
===Program===
 
===Program===
For an explicit example, see [[Frequency meter with a PICAXE 08M2]].
+
====Program without a hardware timer====
 +
For an attempt on the PICAXE 08M2, see [[Frequency meter with a PICAXE 08M2]].
 
#Initiate the display
 
#Initiate the display
 
#Set an interrupt on the pin attached to the switch. Will interrupt the program wherever execution is and go to Interrupt.
 
#Set an interrupt on the pin attached to the switch. Will interrupt the program wherever execution is and go to Interrupt.
Line 39: Line 45:
 
##Convert count to Hz.
 
##Convert count to Hz.
 
##Reset counter.
 
##Reset counter.
 +
====Program with a hardware timer====
 +
For an working example, see [[Frequency meter on Arduino]].
 +
 +
Keep interrupt service routines as short as possible by having them set the minimum amount of variables and instead do the calculations in the main loop.
 +
#Initiate the display
 +
#Set a timer interrupt. Will interrupt the program wherever execution is and go to associated interrupt routine.
 +
#Set a falling or low interrupt on the pin attached to the switch. Will interrupt the program wherever execution is and go to associated interrupt routine.
 +
#Loop:
 +
##If there's a time recorded, note it and erase it.
 +
###If also there's a previous time recorded, calculate frequency.
 +
##If frequency is updated, display frequency.
 +
##Go back to Loop.
 +
#Switch-detecting interrupt routine:
 +
##Record the time now.
 +
#Timer-detecting interrupt routine:
 +
##Increase the time variable.
  
 
===Datasheets===
 
===Datasheets===
 +
;Atmel ATmega328P-PU:28-pin PDIP micro-controller. http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet.pdf
 
;Electronic Assembly ED DOGM081-A:8-character LCD dot matrix display, with SPI serial control. http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf
 
;Electronic Assembly ED DOGM081-A:8-character LCD dot matrix display, with SPI serial control. http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf
 
:Read various forums for discussions on using SPI between the micro-controller and this display. For example, one on how CSB must be used: http://forums.parallax.com/showthread.php/134847-EA-DOGM-162-Display
 
:Read various forums for discussions on using SPI between the micro-controller and this display. For example, one on how CSB must be used: http://forums.parallax.com/showthread.php/134847-EA-DOGM-162-Display
 
:Is the display too dark? The supplied voltage is too high, try to bring it down a bit. I tame a 6V supply with a single 1N914 diode for low power circuits like this.
 
:Is the display too dark? The supplied voltage is too high, try to bring it down a bit. I tame a 6V supply with a single 1N914 diode for low power circuits like this.
;Diodes Incorporated Hall effect switch:http://diodes.com/datasheets/AH180.pdf
+
;Diodes Incorporated Hall effect switch:
 +
:This switch has a long rise and fall time, so it is not good for greater than 8Hz; but it uses very little power.
 +
:http://diodes.com/datasheets/AH180.pdf
 +
;Honeywell SS451A omnipolar Hall-effect digital position sensor
 +
:Works with supplies between 3.0 and 24V, taking 4.5mA at 5V. It switches on at about 85 Gauss and off at about 50 Gauss, in either direction, in less than 1.5µs.
 +
:http://sensing.honeywell.com/index.php?ci_id=45443
 +
;TT Electronics OH090 unipolar Hall-effect sensor
 +
:The OH090 is their most sensitive device, and it switches on and off in less than a microsecond. It requires the magnet to be oriented correctly, since it turns on (voltage drops to zero) when its face is exposed to a field of about 90 Gauss only from the south pole.
 +
:http://optekinc.com/datasheets/OH090-OHS3100.PDF
 
;PICAXE micro-controller system for education:http://picaxe.com
 
;PICAXE micro-controller system for education:http://picaxe.com
  
 
===See also===
 
===See also===
 
See more discussion and other circuits at [[Circuits for teaching physics]].
 
See more discussion and other circuits at [[Circuits for teaching physics]].
 +
 +
[[Bicycle speedometer]] is essentially the same circuit and program, only displaying a different unit, and possibly adding an interface to change the wheel-diameter.
  
 
[[Category:Electronics]]
 
[[Category:Electronics]]

Latest revision as of 13:22, 14 April 2014

Specifications

A 5-digit frequency meter featuring an LCD display.
  • Connect 1 Hall effect switch to watch a magnet passing once per cycle.
    • Hall effect switch may be unipolar or omni-polar, but not bipolar. If unipolar, take care to place magnet correctly.
    • Switching time needs to be shorter than inverse of desired highest frequency.
  • Include a display with at least 4 characters.
  • Include a power switch to save the battery, and/or a reset switch.
  • Use a breadboard so it can be built by students, or modified.
  • Allow timing of periods up to at least 10s, accurate to 0.01s.

One difficult thing about frequency meters is that they operate by counting pulses over a given amount of time, which is only good for steady frequencies, or they count time between two pulses, which gives a period which must be a divisor in a calculation done by the micro-controller often with limited maths abilities. The fact that it is a divisor means that the precision will be inversely proportional to the frequency, in the absence of floating-point maths. The frequency will have a low limit due to the instruction-time of the micro-controller, and an upper-limit due to this divisor effect. It might be possible to add a switch to notify the micro-controller of the expected range.

Circuit

Circuit diagram for a frequency meter featuring an LCD display.

For a detailed, printable diagram, see File:Frequency-meter-Arduino-on-a-board.pdf. For a previous version using a much less precise PICAXE 08M2, see File:Frequency meter-PICAXE-08M2.pdf.

Components

See #Datasheets for specific tips.

  • Breadboard (~$5)
    • Hall effect switch, unipolar or omni-polar, with quick output rise and fall times.
  • Micro-controller. I use an Atmel ATmega328. A previous version used a PICAXE 08M2. (both $3)
    • Resonator circuit if necessary. The ATmega328 uses a 16MHz crystal and two ~20pf capacitors. (~$1)
  • Display
    • LCD Display, serial capable. I use Electronic Assembly's DOGM081 with SPI. ($10)
    • Alternatively, a TTL-to-USB or TTL-to-serial circuit for sharing data with computer ($18)
  • Hook-up wires ($2)
  • Power supply. Our LCD is expecting 4.7V to 5.3V.
A typical 5V regulated circuit, with protective diode and output capacitor. The input voltage must be greater than the dropout voltage of the regulator plus the voltage of the diode plus the output voltage (see a data-sheet).
    • 9V or a quartet of AAA with a 5V voltage regulator and capacitor(s), or
    • 120V AC to 5V DC adapter—I find phone chargers at thrift stores for $1 each, or
    • Three alkaline AAA or AA batteries, or
    • Four NiMH rechargeable batteries, or
    • Three NiMH rechargeable batteries with a 5V voltage booster.

Program

Program without a hardware timer

For an attempt on the PICAXE 08M2, see Frequency meter with a PICAXE 08M2.

  1. Initiate the display
  2. Set an interrupt on the pin attached to the switch. Will interrupt the program wherever execution is and go to Interrupt.
  3. Loop.
    1. Increment time counter.
    2. Display frequency.
    3. Go back to Loop.
  4. Interrupt
    1. Convert count to Hz.
    2. Reset counter.

Program with a hardware timer

For an working example, see Frequency meter on Arduino.

Keep interrupt service routines as short as possible by having them set the minimum amount of variables and instead do the calculations in the main loop.

  1. Initiate the display
  2. Set a timer interrupt. Will interrupt the program wherever execution is and go to associated interrupt routine.
  3. Set a falling or low interrupt on the pin attached to the switch. Will interrupt the program wherever execution is and go to associated interrupt routine.
  4. Loop:
    1. If there's a time recorded, note it and erase it.
      1. If also there's a previous time recorded, calculate frequency.
    2. If frequency is updated, display frequency.
    3. Go back to Loop.
  5. Switch-detecting interrupt routine:
    1. Record the time now.
  6. Timer-detecting interrupt routine:
    1. Increase the time variable.

Datasheets

Atmel ATmega328P-PU
28-pin PDIP micro-controller. http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet.pdf
Electronic Assembly ED DOGM081-A
8-character LCD dot matrix display, with SPI serial control. http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf
Read various forums for discussions on using SPI between the micro-controller and this display. For example, one on how CSB must be used: http://forums.parallax.com/showthread.php/134847-EA-DOGM-162-Display
Is the display too dark? The supplied voltage is too high, try to bring it down a bit. I tame a 6V supply with a single 1N914 diode for low power circuits like this.
Diodes Incorporated Hall effect switch
This switch has a long rise and fall time, so it is not good for greater than 8Hz; but it uses very little power.
http://diodes.com/datasheets/AH180.pdf
Honeywell SS451A omnipolar Hall-effect digital position sensor
Works with supplies between 3.0 and 24V, taking 4.5mA at 5V. It switches on at about 85 Gauss and off at about 50 Gauss, in either direction, in less than 1.5µs.
http://sensing.honeywell.com/index.php?ci_id=45443
TT Electronics OH090 unipolar Hall-effect sensor
The OH090 is their most sensitive device, and it switches on and off in less than a microsecond. It requires the magnet to be oriented correctly, since it turns on (voltage drops to zero) when its face is exposed to a field of about 90 Gauss only from the south pole.
http://optekinc.com/datasheets/OH090-OHS3100.PDF
PICAXE micro-controller system for education
http://picaxe.com

See also

See more discussion and other circuits at Circuits for teaching physics.

Bicycle speedometer is essentially the same circuit and program, only displaying a different unit, and possibly adding an interface to change the wheel-diameter.