Wiki

This version (24 Jul 2012 16:18) was approved by Brett Gildersleeve.

Toggle Counter

Click here to return to the GPIO Conditioning page


The Toggle Counter cell counts the number of edges seen on its input pin and outputs the count as a 28.0 integer value. The toggle detection can be set to detect rising or falling edges on the input.GUI Icon

Input Pins

NameFormat [int/dec] - [control/audio]Function Description
Pin 0: Detection Inputinteger or decimal - controlControl Signal input that is detected by the toggle counter
Pin 1: Interface read inputother - interface registerConnected to a software interface register - reads the last count value at startup

Output Pins

NameFormat [int/dec] - [control/audio]Function Description
Pin 0: Toggle countinteger - controlToggle count. Increments by one each time a new edge is detected on the input.
Pin 1: Interface write outputother - interface registerConnected to a software interface register - writes the last count value

GUI Controls

GUI Control NameDefault ValueRangeFunction Description
N/A33 to 100Sets the toggle count at which the counter resets to zero

DSP Parameter Information

GUI Control NameCompiler NameFunction Description
N/AToggleCountAlg1maxThe maximum value that the counter can reach. When the counter exceeds this value, it will be reset to zero.

Algorithm Description

The toggle counter increments an internal counter each time an edge is detected on the input. Two algorithms exist: one for detecting and counting rising edges, and one for detecting and counting falling edges. In this description, the rising edge algorithm is used as a model.

The counter starts at zero when the program begins. Each time the input detects a rising edge - in any number format - the counter will increment. After the counter exceeds the maximum count value (which can be configured in the GUI), it will reset to zero and resume counting again. The example below shows a rising edge detection toggle counter with a maximum count of 9. Note that since the counting begins at zero, the resulting “staircase” output repeats itself every 10 rising edges.

In the example below, the maximum count value is set at 100. The count er will reset after 101 rising edges have been detected on the input.

Edge detection is done on a sample-by-sample basis. If the current sample exceeds the previous sample, it will be treated as a rising edge, regardless of if the input is really an edge or not.

The example below illustrates this. This is not recommended for a real application of the algorithm. In real applications, input signals should take on only two values, such as logic switches or square waves.

Example

This example shows a Toggle Counter counting a 50 Hz square wave's rising edges. Note that the counter starts at zero, so in this case the counter will go from 0 to 99, resetting every 100 rising edges. Since there are 50 rising edges per second, the Toggle Counter will reset itself to zero once every 2 seconds.

Other cells used in this example - Square Wave, Interface Read, Interface Write, DSP ReadBack

Algorithm Details

Toolbox PathGPIO Conditioning - PushButton - Index Counter - Rising Edge / Falling Edge - Toggle Counter
Cores SupportedADAU144x
ADAU1701
ADAU1761
ADAU1781
“Grow Algorithm” Supportedno
“Add Algorithm” Supportedno
Subroutine/Loop Basedno
Program RAM14
Data RAM4
Parameter RAM1
resources/tools-software/sigmastudio/toolbox/gpioconditioning/togglecounter.txt · Last modified: 24 Jul 2012 16:18 by Brett Gildersleeve