[PASM2] Need help configuring Smart Pin for "pulse/cycles" mode
Cabbage
Posts: 37
I'd like to configure Pin 1 as Smart Pin mode "00100". I've been following the latest "Documentation v35" but I'm a bit baffled by pages 73-75. Anyway here's what I've come up with so far, which doesn't seem to work as I'd expected...
DAT org 'select the standard external 25 MHz crystal hubset #$F0 'configure PIN 1 to be a SMART PIN in mode "pulse/cycle output" (M=00100) { syntax WRPIN D/#,S/# - Set smart pin S/# mode to D/#, ack pin } WRPIN PULSE_CONFIG, PULSE_PIN WXPIN PULSE_X, PULSE_PIN WYPIN PULSE_Y, PULSE_PIN 'just blink a LED on the dev board forever rep @.loop, #0 ' infinite loop drvnot #56 waitx ##12_500_000 .loop '------------------- 'WRPIN syntax: %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0 PULSE_CONFIG long %0000_0000_000_0000000000000_00_00100_0 PULSE_PIN long 1 PULSE_X long $0010_0100 PULSE_Y long $ffff_ffff
I'm running this on a "P2 Eval" board, which appears to have a 25 MHz external crystal. The LED does flash at 1 Hz. I'm using a Saleae Logic to show the pin states.
The problem is that Pin 1 stays HIGH all the time, but I was expecting it to approximate a PWM signal of about 1/16 duty cycle (possibly inverted).
Clearly I've misinterpreted the instructions, what am I doing wrong?
Comments
That hubset looks like a very old version...
Also, I think the crystal is 20 MHz.
You may want to start off with Spin2 first...
You can set the smartpin in one line of Spin2 or Flexprop C code, like done here for NCO:
http://www.rayslogic.com/Propeller2/NCO.htm
Here's a sample of some pure P2 assembly that sets the clock in a way that I think @ozpropdev came up with a long time ago:
Just one other tip...
In Spin2 mode (and also with FlexProp C), you can do inline assembly, which might be easier.
In Spin2, this define in a con section sets the clock automatically:
The hubset example was taken from the v35 documentation (page 58).
The crystal is 25 MHz on my board (no idea why, perhaps it's an old-stock board?? I got it from Mouser in the UK, but it shipped from the USA).
The markings on the crystal aren't very helpful: "6276 T 0806".
Nevertheless the above code does give a near perfect 1 Hz square wave on the LED.
I'm not interested in Spin really, I need the bare-metal performance of PASM for my purposes.
Ultimately I don't need to to very complex things, but I do need to do simple things on MANY channels at once and do them with near perfect determinism. It's... complicated.
In order to get there, I need to learn the quirks of this platform. I'm familiar with the Prop 1 but this P2 is so wildly different it's like starting from scratch. Fun though.
Ok, Looks like "hubset #$F0" switches to the internal fast RC oscillator which is somewhere around 20 MHz. Guess it's 25 MHz in your case.
Doesn't look like you are using the crystal at all.
I'm only aware of 20 MHz crystals being used on any Parallax boards.
BTW: I think that RC fast mode is what you are in after booting anyway. Do you get the same thing if you comment out that line?
This PASM code should work: (see comments for explanation)
Andy
Right, that's a new way to set the clock... "asmclk" is a macro that substitutes in some assembly lines, like the ones above.
Guess that's easier, but I like the @ozpropdev way better...
The same in Spin2:
The timing is the same as with PASM, just easier to write.
If the smartpin does the pulses, it does not much matter if you set it with PASM or Spin, and Spin2 is much faster than Spin on the P1.
Andy
If you have a P2-Eval board then it should only be a 20MHz xtal. AFAIK Parallax never used anything other than 20MHz. P2D2 boards used 25MHz originally.
Someone else, other than Chip, has added it. The "F" is a hack workaround for a known issue with switching PLL modes.
The "0" is selecting RCFAST internal R-C oscillator - which is not crystal locked at all. If you look a little closer at your measured frequency you'll see, although it is close, it isn't really 25 MHz. Chip did a good job of making RCFAST temperature stable too.
PS: The mode number to get the external crystal directly is
HUBSET #%10_10
EDIT: And to use it safely you want to also have the requisite stabilisation steps:
As for the OP source code. There is two fixes: One is the pin's DIR has to be set high to enable the smartpin. The other is related but more obscure. Because DIR is repurposed from controlling the pin to controlling the smartpin, there is, when a smartpin is operating. a bit in the WRPIN mode word for enabling the pin output drive - TT=%01
Ariba has also demonstrated using the built-in symbols to get the same. eg:
WRPIN #P_PULSE + P_OE, #PULSE_PIN 'mode with defined constants
For future reference: DIR is an important control. The base period timer, of those related smartpin modes, runs its own little dance that takes a little wrangling when you want the pulses coordinated at an exact phase alignment. Further reading - https://forums.parallax.com/discussion/comment/1522036/#Comment_1522036
EvanH, if you ever decide to write a P2 book, count me in for purchase.
That certainly strokes the ego.
Appreciated.
I'm way too lazy though. And some credit must go to others' too - For throwing questions and giving their own input. It would be a big list: From Chip's and Eric's tools and docs and Brian's and Cluso's early sources, JMG's curveball questions to Tony's and Andy's snippets and Roger's races with the external RAMs. Even the early streamer work with Mike (msrobot) ... I wouldn't have been motivated without the community here.
I was also going to say I've learned to write better but that's not really the case. It's all down to lots of testing to know a comprehensive explanation.
Thanks all for the tips, I'll try this out over the weekend.
Is there an ETA on a formal datasheet & manual for the P2?
Seems like the forum IS the de facto documentation for this chip. That's great for the community, but not so hot for prospective industrial adopters.
I'm close to being asked to do a formal adoption evaluation of the P2 for work and as it stands I think the current lack of coherent documentation would be a deal-breaker.
That would suck, because I know for a fact that the P2 would be ideal for some of the more exotic projects we have on the roadmap, but I can't prove that to the boss without hard, documentary evidence and probably a working demo too.
I think @"Jeff Martin" will have an update on documentation during the next P2 Live Forum Discussion on May 5.
-- https://forums.parallax.com/discussion/171704/propeller-2-live-forum-early-adopter-series-topics-speakers-and-registration/p1
Hi Jon,
Thank you for the link, I've registered. Looks interesting, perhaps I can get a colleague or two of mine to join in as well.