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

Propeller 1

  • How to pause in PASM
  • How to choose between VAR and DAT
  • WAITPEQ and WAITPNE with PASM
  • IO pin manipulation using PASM
  • Control IO pins from any cog
  • 3D Models for Parallax Products
  • Implementing Abstract Data Structures with Spin Objects
  • Making in USA - The Parallax 8 core microcontroller
  • Simultaneous pin group control
  • Programming the FLiP module over WiFi
  • Keep any value in range
  • Handy Diagnostic Heartbeat
  • Customer Code Deployment in one click

Propeller 2

  • Floating point operators in SPIN2
  • 64/96/128-Bit Unsigned Integer Math
  • 3D Models for Parallax Products
  • DEBUG Plot Layer and Crop
  • Floating point
  • Getting Started Video Tutorials
  • Using the counter for timeouts
  • asmclk and the automatic clock setter
  • Sharing variables between SPIN2 and PASM2
  • Keep any value in range
  • Determine pin state - High, Low or Floating?
View Categories
  • Home
  • Docs
  • Chips Tips
  • Propeller 1
  • Handy Diagnostic Heartbeat

Handy Diagnostic Heartbeat

Reading Time: 1 min read

SPIN

Introduction #

Each of the multicore Propeller 1's eight processors (cogs) has two independent hardware counter modules. Each counter is a configurable state machine for sensing or generating repetitive signals, potentially on every clock cycle.

The counter modules are flexible subsystems that can often take the place of dedicated cogs or peripheral hardware, reducing code complexity and component count in an application.

This handy tip shows how to use one of the counters in a cog to blink an LED. You can start this code in any (or all!) of the cogs, and attached to different LEDs, you can quickly see if one of your cogs stops operating for any reason.

As the counters run in the background, this code will not take up any resources from the rest of your code, and will not interfere with any critical real-time or high speed code loops in the way that traditional threaded processors might.

Here's an example of running the heartbeat in your main cog. You could add the same subroutine to any of your other cogs and call it with a different LED pin to watch as many cogs as you need.

Code Snippet #


CON
    _XINFREQ    = 5_000_000
    _CLKMODE    = XTAL1 + PLL16X
    LED_PIN27   = 27

PUB start

    Enable_HeartBeat(LED_PIN27)
    repeat
        ' loop forever
        ' do something useful here!

PRI Enable_HeartBeat(led_pin)   ' Runs in background via counter A; toggles led_pin

    ''' Configure background counter; set mode and APIN (BPIN is ignored)
    
		''' The shorthand code to configure the counter is (for reference):
    '   ctra := %00100_000 << 23 + 1 << 9 + led_pin
    
		''' The step-by-step way to configure the counter is (as used in this example):
    ctra[30..26] := %00100      ' Mode
    ctra[25..23] := %000        ' Divider
    ctra[14.. 9] := -1          ' Pin B (Set -1 to ignore)
    ctra[ 5.. 0] := led_pin
		
    frqa := 27                  ' Set FRQA so that PHSA[31] toggles the led pin approximately every half second
                                ' - frqa = maximum value of a 32-bit register,
                                '          divided by current clock speed, divided by 2
                                '
                                '        = 2^32 / clkfreq / 2
                                '        = 4,294,967,296 / 80,000,000 / 2
                                '        = 26.8435456  (Round up to 27)
                                '
                                ' Note: The divide by 2 is because the LED will toggle each clock cycle,
                                '       so we want one cycle to be approximately half a second, 
                                '       so that the led will toggle on/off in approximately 1 second.
																
    dira[led_pin] := 1          ' Ensure the led pin direction is configured as an output

For more information about using the Propeller counters, including all the modes and configuration options, check out the links in the Resources below.

Leave your comments here, and ask any questions at our community forums: https://forums.parallax.com


Resources #

https://www.parallax.com/package/an001-propeller-p8x32a-counters

Counter
NCOburst

Was this useful ?
Share This Article :
  • Facebook
  • X
  • LinkedIn
Still stuck? How can we help?

Still stuck? How can we help?

Updated on November 22, 2024
Keep any value in rangeCustomer Code Deployment in one click
Table of Contents
  • Introduction
  • Code Snippet
  • Resources

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