NCO square-wave output using Smartpin
Rayman
Posts: 14,662
in Propeller 2
I wanted a 12.375 MHz square wave to drive the clock on an FTDI EVE3 chip.
Was pretty easy to do using the NCO smartpin mode.
Basically like this in FlexProp C:
in FlexProp C using inline assembly to create NCO on pin #8 (12.375 MHz with 297 MHz P2 clock):
__asm {
wrpin ## 0b00000000000000000000000011001100, #8 //smartpin NCO
WXPIN #12, #8 //base period
WYPIN ##$8000_0000, #8 //add amount per clock
drvh #8
}
I've made some notes on the math and the Spin2 version here.
Was pretty easy to do using the NCO smartpin mode.
Basically like this in FlexProp C:
in FlexProp C using inline assembly to create NCO on pin #8 (12.375 MHz with 297 MHz P2 clock):
__asm {
wrpin ## 0b00000000000000000000000011001100, #8 //smartpin NCO
WXPIN #12, #8 //base period
WYPIN ##$8000_0000, #8 //add amount per clock
drvh #8
}
I've made some notes on the math and the Spin2 version here.
Comments
eg: PINSTART(NCO_PIN, (P_OE | P_NCO_FREQ), 12, $8000_0000)
Try it yourself interactively via the serial console.
Exactly, and pinstart() works also in flex-C if you write it with a underscore at begin: Andy
Thanks!
You're absolutely right. I have recently been porting P1 laser tag code to the P2, and have setup my IR modulation pins manually so that I can control when the oscillation starts. In this case, it is desired right away, so pinstart() is appropriate.