Skip to content
  • Home
  • Account
  • Restricted content
  • OBEX
  • Chips Tips
  • Logout
  • Shop
  • Blog
Propeller OBEX
  • OBEX
  • Forum
Login
Propeller OBEX
View Categories
  • Home
  • Docs
  • Propeller 2
  • Generate a clock with any SmartPin

Generate a clock with any SmartPin

Reading Time: 1 min read

SPIN2

Introduction #

The Propeller 2 can set any of it's Smart IO pins to output a clock frequency without requiring any runtime resources.

Think of Smart Pins as mini microcontroller cores, and every one of the 64 IO's on the P2 microcontroller has one! It means you could set all 64 IO's to be outputting different clock frequencies; but here, let's start with just one!

The topic was discussed in our forums, and here follows a code snippet to demonstrate!

Code Snippets #

This code snippet demonstrates how to set a 3.7MHz clock signal outputting on the IO pin number declared as TEST_PIN.

Yes, it really is that simple! Set the pinstart command and the SmartPin will do the rest!

CON { System timing }

    _CLKFREQ = 180_000_000                                          ' Set the core system clock speed

CON { IO Pins }

    TEST_PIN = 0                                                    ' Set the IO pin to pin 0


PUB start() | freq                                                  ' Define a local variable called 
                                                                    '  "freq" to hold the frequency 
                                                                    '  you'd like to output.

    freq := 3_700_000                                               ' Set the frequency to 3.7MHz, 
                                                                    '  written in Hz as 3700000 or 
                                                                    '  3_700_000 for clarity.
                                                                    
                                                                    
    pinstart(TEST_PIN, p_nco_freq | p_oe, 1, freq frac clkfreq)     ' Start the SmartPin at the
                                                                    '  IO pin stored in "TEST_PIN" 
                                                                    '  in frequency output mode.
                                                                    '
                                                                    ' The command calculates the
                                                                    '  output frequency based on the
                                                                    '  core system clock "clkfreq" and
                                                                    '  the required frequency "freq".
    
    
    ' That's it! Continue the rest of your code here !


Resources #

Parallax Propeller 2 - Spin2 Language Documentation


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

Still stuck? How can we help?

Updated on July 10, 2025
Table of Contents
  • Introduction
  • Code Snippets
  • Resources

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