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
  • Control IO pins from any cog

Control IO pins from any cog

Reading Time: 1 min read

SPIN

Introduction #

The Propeller 1 has 32 I/O pins and 8 processor cores, known as cogs, that allow true real-time parallel processing.

The I/O pins are available to all 8 cogs (cores).

So how do you control them in each cog, and what happens if two or more cogs operate on the same pins?

Explanation #

Each cog has its own set of output registers (DIRA and OUTA) which are combined in the hardware (logically OR'd together) to produce the actual state of the I/O pins.

Each cog also has an INA register, which allows any cog to read the current state of the 32 I/O pins, regardless of whether they're set as inputs or outputs.

Output State #

In each cog that you want to have control over an I/O pin, you must set the DIRA and OUTA registers appropriately:

  • Any cog with a 1 bit in its DIRA register forces that corresponding I/O pin into output mode.
  • Any cog with a 1 bit in its OUTA register and a 1 bit in its DIRA register (same bit numbers) forces that output pin to be high.
  • Any cog with a 0 bit in its OUTA register and a 1 bit in its DIRA register requests that output pin to be low. (Remembering that the outputs are OR'd together; the output will actually be low if no other cog has forced the output high).
dira[pin] := 1        ' Set output direction
outa[pin] := 1        ' Force pin to be high
outa[pin] := 0        ' Request pin to be low
Input State #

In each cog that you want to read an I/O pin, you must set the DIRA register to 0, and then read the contents of the INA register.

dira[pin] := 0        ' Set input direction
value := ina[pin]     ' If pin is low, value = 0   If pin is high, value = 1 

Code Snippets #

These SPIN code methods encapsulate the three basic I/O pin handling requirements:


PUB high(pin)
    ''' Makes pin output and high
    outa[pin] := 1
    dira[pin] := 1

PUB low(pin)
    ''' Makes pin output and low
    outa[pin] := 0
    dira[pin] := 1

PUB input(pin)
    ''' Makes pin input and returns current state (0..1)
    dira[pin] := 0
    return ina[pin]	

Code Example #

This SPIN code example demonstrates using the three methods. When the code runs the first PUB method is always called, which means in this example the "main" method. The example will set I/O pin 7 to high state, I/O pin 8 to low state, and read the value of I/O pin 9 :


CON ' {System Clock Setup}
    _XINFREQ = 5_000_000
    _CLKMODE = XTAL1 + PLL16X

PUB main | value
    high(7)
    low (8)
    value := input(9)

PUB high(pin)
    ''' Makes pin output and high
    outa[pin] := 1
    dira[pin] := 1

PUB low(pin)
    ''' Makes pin output and low
    outa[pin] := 0
    dira[pin] := 1

PUB input(pin)
    ''' Makes pin input and returns current state (0..1)
    dira[pin] := 0
    return ina[pin]

Resources #

Parallax Propeller 1 - Spin 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 March 10, 2025
IO pin manipulation using PASM3D Models for Parallax Products
Table of Contents
  • Introduction
  • Explanation
    • Output State
    • Input State
  • Code Snippets
  • Code Example
  • Resources

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