Skip to content
  • Home
  • Account
  • Restricted content
  • OBEX
  • Chips Tips
  • Logout
  • Shop
  • QuickBytes
Propeller OBEX
  • OBEX
  • Forum
Login
Propeller OBEX

Propeller 2

  • Configuring Visual Studio Code for Programming the P2 on Mac, Windows, and Linux
  • Breakout Board Options for P2 Edge Modules
  • Solar Panel Monitoring Demo (Intro to Using Video 3 of 3)
  • Wireless Programming with the ESP8266 WX Module
  • Brushless DC Motor Control Demo
  • Colorful Terminal Output with ANSI Escape Sequences
  • XBee RF Transparent and API Mode Demo
  • DS3231 Real Time Clock I2C Demo
  • Multiple Servo Control (up to 64) Object
  • Multiple Serial Port (8 UART – 16 Tx/Rx) Object
  • Goertzel Operation with Ultrasonic Transducers
  • Web Page Control of WS2811 LEDs Using the IoT Gateway on Raspberry Pi
  • 320×240 LCD Driver for ILI9341 Controller and XPT2046 Touch Screen
  • Digital Sample ADC to DAC + Analog Frequency to DAC
  • Using Smart Pins to Measure Frequency Output of TSL235R Light-to-Frequency Sensor
  • Ping))) Ultrasonic Distance Sensor with Graphical Debug Demo
  • Simple Analog Input
  • P2 Edge 16 MB Flash Reader and Explorer Utility
  • LED Matrix used as an I/O Test Utility
  • Arlo Conversion to P2 with the Universal Motor Controller
  • Five Buttons On One Pin
  • P2 RTC Add-on Board Demo
  • Simple Video Driver – Using Images (Intro to Using Video 2 of 3)
  • Starting Your P2 Project with a Spin2 Template
  • E-Ink Display Demo
  • MAX7219 LED Display SPI Demo
  • DHT11, DHT22, CM2302 Humidity and Temperature Sensor Object
  • NMEA GPS String Parsing
  • Floating Point Math: DEBUG and Terminal Display Example
  • LEDs – Beyond the Basics
  • Quadrature Encoder Object
  • P2 RTC Add-on with GPS Module
  • DVI/VGA Text Driver Demo
  • PCF8574 I2C LCD Demo
  • Simple Sound Engine Demo
  • 1-Wire Driver with DS18B20 Temperature Sensor Demo
  • Send Email from the Propeller 2 Using the IoT Gateway on Raspberry Pi
  • I2C Device Bus Scanner Utility
  • 32-Channel ADC Object
  • Tetris
  • Video Hardware with Character Map Demo (Intro to Using Video 1 of 3)
  • WS2811, WS2812, WS2812b, WS2813, SK6812x NeoPixel Object
View Categories
  • Home
  • Docs
  • Quick Bytes
  • Propeller 2
  • Goertzel Operation with Ultrasonic Transducers

Goertzel Operation with Ultrasonic Transducers

Reading Time: 2 min read

Description #

The P2 Goertzel circuit measures up to four ADC input signals for magnitude and phase correlation of four internal reference signals, which can also be output to form closed-looped systems.

In this demo, the Goertzel circuit outputs a reference sine pattern to two DAC pins which differentially drive a 40 kHz ultrasonic transducer. Another identical transducer is connected between GND and an ADC pin, so that its ADC bitstream can be used as input to the correlator. On each clock cycle, the correlator multiplies the ADC bit (+1 or -1) by the current reference sine and cosine values, accumulating the products into separate sine and cosine accumulators. The accumulators can be periodically sampled and converted from cartesian to polar form, in order to get the magnitude and phase of the incoming signal(s) relative to the internal reference sine and cosine signals. The Goertzel measurement is done over 1 to 65,534 complete waveform cycles. The more cycles that are measured, the more precise the measurement.

On every clock cycle the Goertzel circuit effectively does this in sequence:

   t := LUT[nco[30:22]] (the LUT can be partitioned in 1/2’s, 1/4’s, etc)
   nco += xfrq (set by SETXFRQ instruction)
   cog_dac_3 := t.byte[3] ^ $80 (cog DAC channel 3 playable on pins %xxxx_11)
   cog_dac_2 := t.byte[2] ^ $80 (cog DAC channel 2 playable on pins %xxxx_10)
   cog_dac_1 := t.byte[1] ^ $80 (cog DAC channel 1 playable on pins %xxxx_01)
   cog_dac_0 := t.byte[0] ^ $80 (cog DAC channel 0 playable on pins %xxxx_00)
   sin := t.byte[3] sign-extended
   cos := t.byte[2] sign-extended
   m := ADC_bit ? 1 : -1
   sin_accumulator += sin * m (32-bit sin accumulator)
   cos_accumulator += cos * m (32-bit cos accumulator)

After each XCONT, GETXACC can read and clear the accumulators in one clock cycle:

   capture sin_accumulator for conveyance to GETXACC’s D
   capture cos_accumulator for conveyance to next instruction’s S
   sin_accumulator := sin * m (clear to current sin * m)
   cos_accumulator := cos * m (clear to current cos * m)

The Goertzel circuit may also be used to simply detect magnitude of a frequency within a noisy signal. In that case, no reference outputs would be needed, because there is no feedback loop.

Parts Used #
  • P2 Edge Module
  • P2 Edge Breadboard
  • (2) Ultrasonic Transducers
Source Code #
  • Goertzel_ultrasonic.spin2
Programming Language #
  • Spin 2
  • PASM2
Tools and Operating System #
  • PNut
  • Propeller Tool for Windows
Additional Resources #
  • Propeller 2 Spin Documentation
  • Super Clean Goertzel Operation with Ultrasonic Transducers (P2 forum thread)
  • Graphical Debug Tools in Spin2
Document Author #
  • Chip Gracey
Source Code Author #
  • Chip Gracey
Was this useful ?

Share This Article :

  • Facebook
  • X
  • LinkedIn
Still stuck? How can we help?

Still stuck? How can we help?

Updated on September 29, 2026
Multiple Serial Port (8 UART – 16 Tx/Rx) ObjectWeb Page Control of WS2811 LEDs Using the IoT Gateway on Raspberry Pi
Table of Contents
  • Description
  • Parts Used
  • Source Code
  • Programming Language
  • Tools and Operating System
  • Additional Resources
  • Document Author
  • Source Code Author

Copyright © 2026 - Parallax Inc.
599 Menlo Drive | Rocklin, CA 95765 | USA