Propeller 2, What does "%00110 NCO Frequency mode" do?
JonTitus
Posts: 193
in Propeller 2
I'm puzzled by the description of the Prop-2 "NCO Frequency." Couldn't find an example I could understand.
What does this mode do and what would someone use it for?
What should I see on my scope at the Smart-Pin output pin? A short assembly-language example would help. So would a diagram that shows what the Smart-Pin output would look like.
Specific questions re the documentation:
1. "Upon WXPIN, X[31:16] is written to Z[31:16]..." What does this value represent?
2. "Y[31:0] will be added into Z[31:0] at each base period." Where does the Y value come from and what does it do?
I volunteered to help clarify the Prop-2 documentation and appreciate the help of Forum members. Thanks. --Jon
What does this mode do and what would someone use it for?
What should I see on my scope at the Smart-Pin output pin? A short assembly-language example would help. So would a diagram that shows what the Smart-Pin output would look like.
Specific questions re the documentation:
1. "Upon WXPIN, X[31:16] is written to Z[31:16]..." What does this value represent?
2. "Y[31:0] will be added into Z[31:0] at each base period." Where does the Y value come from and what does it do?
I volunteered to help clarify the Prop-2 documentation and appreciate the help of Forum members. Thanks. --Jon
Comments
edit: updated scope image links & corrected a code paste
See the attached for a prototype of how we might better explain a Smart-Pin operation. Let me know what you think. --Jon
Your "wrpin Pulseconfig, #20" is simply a value and a pin number for wrpin. In Forth you would just test your assembly code this way:
I purposely used your absolute values rather than symbols or constants, but by all means define them and use them if you like the same way.
Of course there are higher level functions which already set it to NCO mode and default prescale and period. But you can do it the long way too and directly translate that into assembly or vice-versa.
I would add after sentence "Software sets..."
Therefore the width of the high pulse is calculated by X[15:0] less X[31:16].
A comment prior to the "IN Flag" in the diagram "(on the second last pulse end)"
From the calculations based on 25MHz clock which I calculated that you used
X[15:0] = 1500 x 40ns = 60us
X[31:16] = 500 x 40ns = 20us
So I would replace this line
PulseTiming long $01F4_05DC '60 usec pulse, 20 usec logic-0
with
In your example you state the following. The DIRH/L doesn't control the output ibversion. It is done by the low level pin control bit (O).
The SmartPin NCO Frequency mode acts very similarly to the P1 Counter NCO mode.
When running, every X[15:0] system clocks Y[31:0] is added to Z[31:0]. The output pin will be set to Z[31].
While setting up, when you do the WXPIN instruction, X[31:16] is copied to Z[31:16]. This just offsets the initial Z value so that you can phase adjust the frequency (aka start already partially into the cycle). X[31:16] is not used after that.
With NCO Frequency mode you do not control the high and low time (it's always 50% duty). You are just controlling the frequency.
If X[15:0] is set to 1, then Y[31:0] will be added to Z[31:0] every system clock tick. So in order to set the frequency you desire you need to calculate how many system clocks one cycle of your given frequency takes. This can be done by using "qfrac desiredFrequency, systemClockFrequency" and then "getqx valueForY".
If you set X[15:0] to 100, then Y[31:0 will be added to Z[31:0] every 100 system clock ticks. Thus your output frequency would be divided by 100 (e.g. 100kHz would become 1kHz).
As for why? Well there are lots of reasons you might want to have a pin toggle at a given frequency. Sound, leds/lights, driving some external device's clock input, and much mode.
When Y is a whole division of 2^32, eg: $8000_0000, then it produces a simple square wave at the pin output (smartOUT). Y = $8000_0000 will toggle smartOUT on completion of each X period.
When Y is not a whole division of 2^32 then it manifests as a dither at the output. This can be good for some applications but can create interference for other applications so best bet is start with nice clean fractions.
PS: Educational trivia: X = 1 and Y = $0080_0000 produces the same frequency (sysclock/512) as X = $100 and Y = $8000_0000.
Where: Pin, Frequency, Continuous, DutyCycle, Start & Stop, etc - would be called variables / predefined functions to PASM2 code.
In line with what Jon Titus listed for a NCO mode Smart Pin prototype App note or document.
SineWave( Pin, Frequency, Continuous)
SineWave( Pin, Frequency, Cycles )
SineWave( Pin, Frequency, DutyCycle)
SineWave( Pin, Frequency, Start )
SineWave( Pin, Frequency, Stop )
SquareWave( Pin, Frequency, Continuous)
SquareWave( Pin, Frequency, Trigger )
SquareWave( Pin, Frequency, OneShot )
SquareWave( Pin, Frequency, DutyCycle)
SquareWave( Pin, Frequency, Start )
SquareWave( Pin, Frequency, Stop )
TriangleWave( Pin, Frequency, Continuous)
TriangleWave( Pin, Frequency, Trigger )
TriangleWave( Pin, Frequency, OneShot )
TriangleWave( Pin, Frequency, Start )
TriangleWave( Pin, Frequency, Stop )
SawtoothWave( Pin, Frequency, Continuous)
SawtoothWave( Pin, Frequency, Trigger )
SawtoothWave( Pin, Frequency, OneShot )
SawtoothWave( Pin, Frequency, Start )
SawtoothWave( Pin, Frequency, Stop )
Should read? I know little about setting the Prop-2's operating frequency.
That works.
There's nothing in the example that sets the clock frequency. Maybe we assembly language newcomers should know that, but there's no documentation I could find about how to set the clock. Maybe I missed it.
The two comments are a good start, but what do the other commands do? Please explain the math so we can understand the qdiv, getqx, and qfrac instructions. We can see them in the op-code spreadsheet but seeing the numeric results in the comments helps us understand what the instructions do, why you used them, and how we can use them. Examples, in my opinion, should aim to teach people how to do things, not just demonstrate them.
Also, what is "pa," a register? The "PA" appears in the Prop-2 docs six times, none of which explain what it is, what it does, and why you used it. That information would helps us newcomers.
Thanks for taking the time to send your example. I now see a square wave, but still don't understand the calculations and the results you used to produce it. --Jon
Yes the code I posted was a snippet.
I would have to post multiple examples that work for all the compilers.
BTW The code you posted is incomplete and won't work straight up either.
Here's another example that is for SPIN2.
The calculation is Y = (Hz << 32) / clock frequency.
PA is one of the special function registers in the Propeller 2.
PA and PB are mainly used with LOC instructions with PTRA and PTRB.
I am using it as a general prpose register.
Math was reduced to a simpler form same as SPIN2 example above.
I also added some comments Andy
It is built from Cluso's original post - https://forums.parallax.com/discussion/comment/1452025/#Comment_1452025 but with one notable change: The first HUBSET #$f0 is a workaround for a hardware flaw that was later found in the sysclock switching circuit.
I think you missed the section of the docs on COGRAM and registers:
PA and PB are also set by XBYTE to current bytecode and hub address of next bytecode in FIFO, respectively.
Back in the late 1960's, Digital Equipment Corp (long gone) published a book, "Introduction to Programming" for people who wanted to learn assembly-language programming for the company's PDP-8 minicomputers. It's an example of excellent documentation and I recommend anyone writing the Prop-2 assembly-language docs get a copy. The Prop-2 is orders of magnitude ahead of the old PDP-8's, but good documentation techniques are timeless. Abebooks.com has several copies for about $US 15. ISBN 13: 9780395747117. --Jon
In this case, just look up the CALLD, CALLPA and LOC instructions in the instruction sheet (altough last I checked, CALLD's description was a bit confusing)
SetDCvolts( 15, 1378, DCmilliVolts, Continuous ) = Happy camper! Love the P2 !!!
My project is a success...
But did you read and understand this bit?:
In the example in question it is being used as a general purpose register that happens to have a name.
If the original example had been would you have found that less confusing and more newbie friendly? Maybe if it was given a different name for this use case?
What I'm finding confusing is that you initially noted the state of the documentation, offering to contribute to cleaning it up, and then when asking for clarifications you appear to complain about the state of the documentation.
It has been acknowledged by many that the documents aren't newbie focussed, and need more work. I'd humbly suggest that simply asking for further clarification, rather than telling people that a given explanation won't mean anything to a newbie, is probably a better approach to this.
We have all been newbies at some point, and this community seems to maintain sympathy for newbies quite well. Some of us might take shortcuts with our explanations, but I've never seen anyone here refuse to slow down and provide a deeper understanding when asked for it.
Such a library hasn't been published yet. Are you volunteering to write it?
Most of the material available has been developed by, or in collaboration with, volunteers because Parallax isn't a huge corporation and they have taken on a fairly huge undertaking.
To setup P50 as a 12-bit DAC:
At any time to output a voltage (in millivolts), say 1.852 volts
But there is nothing to these functions though, they are very simple. There are just two lines: and
So surely those functions could be added on the fly to suit.
edit: Since I revisited this function I decided I should just call it "mV" instead and have it automatically set the DAC mode, plus I apply about 5mV compensation to recalibrate it. When I enter 825 mV I get 825mV.
Now I just connect a meter to P52 and type "52 PIN 825 mV" and the meter reads .825V
I have started to revise the SMART-PIN section of the Prop-2 reference and in explanations of two modes I have included a figure that shows timing of signals and several example codes. Several people have looked at these revisions and have commented on them. I do not use any special registers, just simple variable names, and each piece of code will operate as is--no snippets that rely on things someone might not know about. Trying to keep explanations simple and clear. I'll continue to work away at revisions for each of the Smart-Pin modes. I complain about poor documentation when I cannot understand it and usually get helpful comments so I can revise or recreate it. You'll find an example as an attachment to one of my posts close to the start of this thread. I welcome comments.
My complaints about the Prop-2 documents might spur others to offer revisions, too.
Currently there are very few (if any) novices here. The docs have been quickly compiled for those "in the know". Where they lack details for us long-timers, we just ask and someone with more expertise in that area can nut it out, try it out if time permits, and report back. Sometimes we have to ask the "master". Unfortunately, time often limits us putting this info back into the documents.
Add to this, documentation experts are usually not engineers. We tend to use a different part of the brain.
But we will get there. And many thanks to those who help along the way
The main google doc is not intended as a beginners instruction manual. It is the technical reference for testing the hardware while it was being finished, also for tools developers and for the hardy folks that enjoy a challenge. And it'll likely continued to be referenced long into the future because of its extensive coverage.
In fact I thought you had made it your mission to work through it piece by piece, writing alternative sections in simpler descriptions and with examples.