Welcome to the Parallax Discussion Forums, sign-up to participate.

# Fastest that you would or could toggle an IO pin?

Posts: 2,551
edited August 2012
I am getting mixed answers in my searching so I figured I would ask my question directly. Irregardless of what the propeller can do as far as speed of toggling a pin, in most uses of a propeller, what is the fastest you would toggle an IO pin? For example, I know my Honda is spec'd to do 110mph, but I never need to go over 75.

I also need to answer the same question for a BASIC Stamp because my project ties into both.

Update 8/31/12
In SPIN, I was able to obtain 18KHz
In PASM, I was able to obtain 5MHz as a 50% duty cycle with a XOR loop.
With Counters, I was able to obtain 60MHz through my translators which was my goal. I did go to 80, but the translators output was very unstable.
Andrew Williams
WBA Consulting

• Posts: 2,713
edited May 2012
I think...

Using a counter, you can output a ClkFreq/2 square wave (ie 40~50MHz depending on 5~6.25MHz xtal)
Or in single cog Pasm, about 10~12.5 MHz

Your Honda, whats it go to 6000rpm? Thats 100 Hz, or 500,000 times slower :)
• Posts: 352
edited May 2012
hmm.

I think what's really being asked is how long it takes for a spin statement to turn on, and then turn off, a single output pin.

rough estimate is that I was just barely able to get 38 KHz IR working with just spin instructions with an 80 MHz clock.
subsequent revisions used a counter, of course, to produce the 38 KHz modulation and then much more slowly stream out the bits using spin.
• Posts: 1,464
edited May 2012
If using the PLL, the max I've been able to see is 230Mhz with 80MHz system clock.

If PASM, 10Mhz, 1 instruction on, 1 off.
• Posts: 1,146
edited May 2012
Find out for yourself. But determine whether you are using spin or pasm. There (big duh please) is a huge difference in speeds. What will your project require to meet your needs? Then set up loops of different functions to get a feel for timing. Not just a toggle on/off as that may give an absolute speed, but would not be very representative of what you will get.

An example test I ran was step through all 4096 values into a 12bit mdac to put out a ramp function. In spin it took multiple seconds to run from 0 to 4096. In PASM, the same ramp would take about 18 mS. So maybe it would make better sense to evaluate whether the chip specs can deliver on the project.

FF
Ordnung ist das halbe Leben....
Ich lebe in der anderen H
• Posts: 1,088
edited May 2012
<-- Hit the speed limiter on a Honda :)

I've toggled a pin at 9000hz, so on for 4444 clk cycles and off for 4444 clk cycles, for my automotive project. (15k rpm) This was in PASM and spin, although with spin I had nothing else in the loop besides the pin toggle code, because it is so much slower. If you can spare a dedicated cog to spin, this will be fine. If you have other stuff going on, PASM is the way to go IMO.

I am getting mixed answers in my searching so I figured I would ask my question directly. Irregardless of what the propeller can do as far as speed of toggling a pin, in most uses of a propeller, what is the fastest you would toggle an IO pin? For example, I know my Honda is spec'd to do 110mph, but I never need to go over 75.

I also need to answer the same question for a BASIC Stamp because my project ties into both.
• Posts: 12,297
edited May 2012
The counters can toggle at clock speed, so an 80MHz clock can toggle at 80MHz. Using the internal PLL in the video counter can toggle faster - IIRC up to 2x clock speed. PASM can do clock/8 (2 sets of 4 clocks for 2 instructions but of course will top out when you need a jump instruction. Spin is much slower, typically ~50 pasm instructions per spin simple instruction.

FYI: FUllDUplexSerial will run at 115,200 quite happily - some have run it faster IIRC. That is 115,200 bits per second.
My Prop boards:
Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
Website: www.clusos.com
• Posts: 2,554
edited May 2012
I tried toggling a pin on a plain old BS2 and got 1.19 kHz out.
- Rick
• Posts: 5,035
edited May 2012
I don't think the question is asking for the fastest possible speed, but the fastest speed that most code runs at. I.e., if you averaged the maximum speed of I/O toggling of every object in the Obex, what would that speed be?
• Posts: 2,551
edited May 2012
Some very good answers and details to help me along, but SRLM is correct as I am trying to determine if a 30mhz limit on IO pins would limit the propeller's functionality.
I was at the conclusion that toggling a propeller pin at 80mhz was possible, but why would you need to? A better way to ask my question is probably: If you can't toggle a pin over 30mhz, what can the propeller NOT do that most propeller users would be doing. If I hand you a propeller board that cannot go faster than 30mhz on an IO pin, could you still use it?

Rdl2004: thanks, I was figuring the stamp would be way under my 30mhz breakpoint.
Andrew Williams
WBA Consulting
• Posts: 7,101
edited May 2012
For mechanical systems the fastest I need to toggle a pin for would be a 20,000 rpm bldc motor (3 phases/windings) which is 1 KHz. For data acquisition more than 1MHz is rarely needed. Fastest ever was 96MHz for acquiring data from a PMT but that was done in hardware.
In science there is no authority. There is only experiment.
Life is unpredictable. Eat dessert first.
• Posts: 9,074
edited May 2012
Some very good answers and details to help me along, but SRLM is correct as I am trying to determine if a 30mhz limit on IO pins would limit the propeller's functionality.
I was at the conclusion that toggling a propeller pin at 80mhz was possible, but why would you need to? A better way to ask my question is probably: If you can't toggle a pin over 30mhz, what can the propeller NOT do that most propeller users would be doing. If I hand you a propeller board that cannot go faster than 30mhz on an IO pin, could you still use it?

Only for some things - remember the Prop can also resolve any pin edge to 12.5ns, so any Bandwidth limit restricts the corner cases on both generate, and sync.

A better question is, what drives the need to limit a pin BW to 30MHz ?
• Posts: 2,012
edited May 2012
Some very good answers and details to help me along, but SRLM is correct as I am trying to determine if a 30mhz limit on IO pins would limit the propeller's functionality.
I was at the conclusion that toggling a propeller pin at 80mhz was possible, but why would you need to? A better way to ask my question is probably: If you can't toggle a pin over 30mhz, what can the propeller NOT do that most propeller users would be doing. If I hand you a propeller board that cannot go faster than 30mhz on an IO pin, could you still use it?

Rdl2004: thanks, I was figuring the stamp would be way under my 30mhz breakpoint.

With a 30 MHz limit you can not do SigmaDelta ADC and DutyPWM output. If Duty not works then for example all the sound object that use DUTY mode for DACs will not work well.

With 30 mhz (=0.03 Hz) you can not do much more than blinking a LED very slow.

Andy
• Posts: 1,539
edited May 2012
kwinn wrote: »
For mechanical systems the fastest I need to toggle a pin for would be a 20,000 rpm bldc motor (3 phases/windings) which is 1 KHz. For data acquisition more than 1MHz is rarely needed. Fastest ever was 96MHz for acquiring data from a PMT but that was done in hardware.

Rather off topic but a BLDC motor at 20,000 rpm the frequency depends on the number of magnet pole pairs, not the number of windings, each winding sees one cycle per pole-pair. I've some brushless BLDCs with 7 pole pairs so the windings would run at 2.33kHz for 20,000rpm, but the time step between each phase switching would be 1/6 of that period, i.e. 71.4us - in the PASM range clearly.

Pet peeve for previous posters: mhz ?? KHz ?? really?? Those mean 0.1 'z' and 1024 hertz respectively (m = milli = x0.001, h = hect = x100, K = x1024 (not SI) hertz is abbreviated Hz not hz)
• Posts: 2,551
edited May 2012
jmg wrote: »
A better question is, what drives the need to limit a pin BW to 30MHz ?
I am working on a propeller pcb design that will have another chip between the prop and the io pin. The particular chip I am currently looking at has a switching limit of 30mhz (megahertz) ;-)
Andrew Williams
WBA Consulting
• Posts: 9,074
edited May 2012
I am working on a propeller pcb design that will have another chip between the prop and the io pin. The particular chip I am currently looking at has a switching limit of 30mhz (megahertz) ;-)

So there must be some as yet unstated benefit of that chip, and it presumably does not go between ALL Prop Pins, and the real world ?
Dedicated IO functions are fine, provided users still have some choice.
Plenty of designs have RS232 chips, or Darlington Arrays on some of their pins.
• Posts: 20,594
edited May 2012
I am working on a propeller pcb design that will have another chip between the prop and the io pin.
What is the other chip, and what is it's purpose? We could help you better if you were less coy about your intentions. :)

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.

-Antoine de Saint-Exupery

We had many discussions at the galley table and there had been many honest attempts to understand each other's thinking. There are several kinds of reception possible. There is the mind which lies in wait with traps for flaws, so set that it may miss, though not grasping it, a soundness. There is a second which is not reception at all, but blind flight because of laziness, or because some pattern is disturbed by the processes of the discussion. The best reception of all is that which is easy and relaxed, which says in effect, "Let me absorb this thing. Let me try to understand it without private barriers. When I have understood what you are saying, only then will I subject it to my own scrutiny and my own criticism."  This is the finest of all critical approaches and the rarest.

The smallest and meanest of all is that which, being frightened or outraged by thinking outside or beyond its pattern, revenges itself senselessly; leaps on a misspelled word or a mispronunciation, drags tricky definition in by the scruff of the neck, and, ranging like a small unpleasant dog, rags and tears the structure to shreds.

-John Steinbeck, The Log from the Sea of Cortez
• Posts: 2,551
edited May 2012
Phil, et al,
My apologies, but there are many caveats to the design that are as yet undisclosed purposely, so forgive my attempts to get detailed answers from a non-detailed question. After more thought and an email from someone who has some knowledge of the design, I have been able to confirm that the 30mhz limit will pose minimal issues for my design's main intent. The secondary intent of the design will only have concerns among 10-20% of those users, so overall, less than 5% of my target market will be saddened by the limit.
Andrew Williams
WBA Consulting
• Posts: 2,551
edited August 2012
Update: I have my design in prototype stage and I am trying to "break it". For more detail, I am using voltage translators with the prop that are rated at 60Mbps (TXS0108E). I am trying to get the prop to surpass that by using PASM and counters to toggle a pin. Earlier in this thread it is mentioned that 10Mhz should be possible in PASM. The best I can get is 6.684Mhz (on my board and my PropBOE.

Can anyone tell me why my PASM code is not faster than that? I am using a modified version of Jonnymac's JM_Blinker code. I still need to dig deeper into counters to try to get to 40Mhz as reported being possible.
```'' =================================================================================================
''
''   Author..... Jon "JonnyMac" McPhalen
''   E-mail..... jon@jonmcphalen.com
''   Started....
''   Updated....  Andrew Wiliams, PASM Toggle Speed
''
'' =================================================================================================

CON
_clkmode  = xtal1+pll16x
_clkfreq  = 80_000_000

var

pub start

dat

org     0

blinker                 mov     t1, par                         ' start of structure
mov     dira, pinmask                   ' make pin an output

bloop                   andn    outa, pinmask                   ' pin off
or      outa, pinmask                   ' pin on
jmp     #bloop                          ' loop forever

' --------------------------------------------------------------------------------------------------

ontix                   res     1                               ' on timing in system ticks
offtix                  res     1                               ' off timing in system ticks
timer                   res     1

t1                      res     1
t2                      res     1

dat

{{

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

}}

```
Andrew Williams
WBA Consulting
• Posts: 9,074
edited August 2012
Earlier in this thread it is mentioned that 10Mhz should be possible in PASM. The best I can get is 6.684Mhz (on my board and my PropBOE.

Can anyone tell me why my PASM code is not faster than that?

It depends on semantics - you have a Set/Clr/Jmp, in a 3 op code loop. You have one Pin-cycle per loop (not 50% duty), so 6.6666' MHz is the result.
You can do a XOR+JMP and now the loop runs at 10MHz, but a 10MHz toggle is a 5MHz pin frequency.

Or you can unroll the loop and chain XOR, for a 20MHz toggle burst, or a 10MHz pin frequency burst, for tests.
• Posts: 6,095
edited August 2012
In Tachyon a normal bit-bashed SET and CLR will generate a 178.6kHz frequency but if I use the OUTCLK which toggles a pin I can get 416.7kHz.
#11 MASK BEGIN DUP OUTSET DUP OUTCLR AGAIN
#11 MASK DUP OUTSET BEGIN OUTCLK AGAIN
Brisbane, Australia
• Posts: 2,551
edited August 2012
Well that's just too easy. I updated to the XOR+JMP and now it's 5MHz for a full pin toggle cycle which makes sense to me now. Now I am off to messing with counters to get to the next level......
Andrew Williams
WBA Consulting
• Posts: 3,623
edited August 2012