Here's a quick example of how to provide a high frequency output on a Propeller's GPIO pin.
Frequencies far above the actual CPU's clock speed can be generated with excellent resolution. In experiments I have found that 180MHz is achievable, although the signal degrades from a square wave to an approximate sine wave with reduced amplitude when measured directly on the Prop's pin.
The Propeller cog can set up this output and continue performing other tasks as the frequency generation doesn't take any run-time once initiated. The code below outputs a square wave at Pi megahertz (3,141,593Hz) by setting up Counter A in PLL single ended mode (00010) and setting FRQA to the value 10541436. This value is calculated using this equation...
So, working this out using a standard 5MHz crystal, the highest PLL multiplier (pll16x) and a PLLDIV value of "divide by 1"...
Frequencies far above the actual CPU's clock speed can be generated with excellent resolution. In experiments I have found that 180MHz is achievable, although the signal degrades from a square wave to an approximate sine wave with reduced amplitude when measured directly on the Prop's pin.
The Propeller cog can set up this output and continue performing other tasks as the frequency generation doesn't take any run-time once initiated. The code below outputs a square wave at Pi megahertz (3,141,593Hz) by setting up Counter A in PLL single ended mode (00010) and setting FRQA to the value 10541436. This value is calculated using this equation...
FRQA = (DESIRED_FREQ_IN_HZ * (2^32)) / ((XTAL_FREQ_IN_HZ * CPU_PLL_MULTIPLIER * 16) / PLLDIV_MODE)
So, working this out using a standard 5MHz crystal, the highest PLL multiplier (pll16x) and a PLLDIV value of "divide by 1"...
10541436 = (3141593 * 4294967296) / ((5000000 * 16 * 16) / 1)
Setting the FRQA register to this value causes the Counter A subsystem in the current cog to output the desired frequency.
Each cog has 2 such counters, each of which is independent of the others. So if you wanted to you could output 16 different frequencies from the same chip while still using zero CPU time. Pretty cool.
Turning the counter on and off in code will let you create a simple CW signal at your chosen frequency, if you have a Ham radio licence of course.
Changing the value of FRQA while the signal generation is running allows you to modulate the signal's frequency on the fly (as in FM radio)!
Each cog has 2 such counters, each of which is independent of the others. So if you wanted to you could output 16 different frequencies from the same chip while still using zero CPU time. Pretty cool.
CON
_clkmode = xtal1 + pll16x '80Mhz cpu speed
_xinfreq = 5_000_000
PUB main
coginit(0, @ASM_ENTRY_POINT, 0)
'----------------------------------------------
DAT
org 0
ASM_ENTRY_POINT
or dira, HF_PIN 'set pin as output
mov FRQA, FREQ 'set up the desired frequency
mov PHSA, #0 'set the phase back to 0 (optional)
mov CTRA, CTRA_MODE'begin output of the HF signal
waitpeq $, #0 'sleep forever
'----------------------------------------------
HF_PIN long |< 15 'output on pin P15 (physical pin 20)
FREQ long 10541436 '3.141MHz (see calculation)
CTRA_MODE long %0_00010_111_00000000_000000_000_001111
FIT
Changing the value of FRQA while the signal generation is running allows you to modulate the signal's frequency on the fly (as in FM radio)!