Shop OBEX P1 Docs P2 Docs Learn Events
How Fast Can You Flip a Pin? Put Code Here. — Parallax Forums

How Fast Can You Flip a Pin? Put Code Here.

HumanoidoHumanoido Posts: 5,770
edited 2012-10-15 00:49 in Propeller 1
Using a Counter, 12.6-ns to a side.
[FONT=Verdana][FONT=&amp][FONT=courier new]CON[/FONT][/FONT][/FONT][FONT=courier new]
                 ' Declare constants, Feedback/PLL multiplier  
  _clkmode = xtal1 + pll16x  
                 ' External oscillator 6.25 MHz Crystal for 100MHz
  _xinfreq = 6_250_000      
                 ' 200MIPs, 25MIPs/Cog PUB Toggle3(Pin)
                 'Use cog's counter module, toggle at clock speed
dira[Pin]~~      'Set I/O pin to output
                 ' mode PLL BPIN APIN
ctra := 100_000 << 23 + 1 << 9 + Pin
                 'Establish mode and APIN (BPIN ignored)
                 'Set FRQA so PHSA[31] toggles every clock
frqa := $8000_0000
repeat           'Infinity loop[/FONT]

Comments

  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-06 19:46
    Actually that was code for faster 10-ns toggle using the 6.25 crystal.
    I wonder if the generator can be used to toggle a pin faster?
  • frank freedmanfrank freedman Posts: 1,983
    edited 2012-10-07 01:40
    To what purpose would this be used? For just toggling a pin w/ no intelligence to it, might as well use an osc into the appropriate conditioning circuit rather than wasting a whole cog........ Maybe asked by an electronics cannon lawyer? Props have pins too. ;)
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-07 02:54
    To what purpose would this be used? For just toggling a pin w/ no intelligence to it, might as well use an osc into the appropriate conditioning circuit rather than wasting a whole cog........ Maybe asked by an electronics cannon lawyer? Props have pins too. ;)
    It's purely an academic challenge but I would probably build it and some applications could follow. Keeping the program with one cog is ok. If more cogs make the pin toggle faster, that's ok too. Can you provide more insight about how to use the oscillator and pin?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-07 03:13
    My impression is 'that's nice'. From reading PDFs for 74xxxx logic chips of various types, I seem to recall that a lowly inverter, like a 74LS06 can't handle faster than 7 nano seconds, and 15 ns might be the actual performance of some chips. So 10 seems a bit fast for nearly everything I want to do that connects with the real world.

    Just consider that visual blinks of an LED can't be seen a rates much over 30 times a second. (30Hz)
    Music and synthesized sounds cannot be heard above 20,000Hz.

    Things like rapid button pushing with de-bounce and LCD interfacing tend to be even slower that 30Hz.

    So what's the rush to hit the speed limit? There are tons of creative things that can be done with a 5Mhz Xtal and you don't have to risk destruction of the Propeller or provide it with excessive power.

    In fact, I tend to be more interested in running the Propeller as slow as possible so that I can build a device that operates for many days on one battery. With speed, you have to have an umbilical cord to the Mains.

    In some ways, you are making it more difficult for applications to follow. I have tried to focus on taking that 3.3 volts at about 2-3ma and have it drive a 1/4 horsepower motor or an 1800 watt heating element. There are loads of questions about how to do this ruggedly and with what I can easily get in Taiwan.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-07 03:28
    BTW, if you really want to use all the Propeller's speed and to use it well, try applying it to search data, to sort data, or to resolve complex computations. Toggling I/O pins will always hit speed barriers as the real world slows responses to fit human senses.

    Much as it has been hard for me to study them, searching and sorting algorithms are important.
  • Mark_TMark_T Posts: 1,981
    edited 2012-10-07 03:40
    I wonder if the generator can be used to toggle a pin faster?
      ctra := %010_111 << 23 + Pin  ' PLL single ended, PLL divide-by 1.  Note the % (!)
    
      frqa := $1999_9999                 ' 8MHz into PLL, PLL multiplies by 16 -> 128MHz out (maximum PLL rating)
      repeat  
    

    Though I can get upto at least 140MHz by increasing the FRQ value
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-10-07 03:51
    PropForth uses this all the time to derive the XI clock signals when running in one of its multi-propeller configurations. The master propeller, running PropForth can provide clock and EEPROM services to a slave propeller. The slave only needs to have decoupling caps and power. I do it all the time. Being able to run the counters in a COG is neither a big revelation or a major programming feat.

    One master Propeller can run up to 4 slaves this way before it runs out of I/O pins. With a full configuration, you have 112 USABLE I/O pins and 27 COGs you can work with interactively through the Forth interpreter each is running.

    This is an ACTUAL multi-propeller configuration that has been documented and duplicated by others with code the is FREELY available and EASILY found on the forum.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-07 04:00
    I wasn’t really thinking about those slow things although Lab projects began with flashing LEDs. Plus, I’m saving that idea for another thread - “how slow can your propeller go?”


    The magnitude of ns is often applied to telecommunications, pulsed lasers, areas of electronics, and for the Lab, nanoscopic machines, nano pulsars, fast time base windows, measurement yardstick for the microscopic, particle references, travel speedometer for electromagnetic radiation, i.e. a tool for referencing speed in various substances with the index of refraction, a base for cold fusion and other fusion reactions, molecular microscopy, and undoubtedly a clock for high speed event objects internal and external to the chip.


    Example of NS Events
    0.5 - average life of some molecules
    0.1 - cycle time for radio frequency 1 GHz, an inverse unit
    1.017 - time for light to travel one foot
    3.3356 - light travels 1 meter in a vacuum
    10 - one generation of a chain reaction (nuclear)
    12 - half life of K Meson
    100 - cycle time for 10MHz frequency


    Although we measure the propeller chip in millions of instructions per second, relatively speaking, one could just as easily offer measurements in the number of calculations per nanosecond. For example, a cog can reach a theoretical 20 MIPS which is one instruction every .00000005 second. This is equal to one instruction every 50 nanoseconds. However it may sound faster calling it one instruction every .05 microsecond.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-07 05:01
    Mark_T wrote: »
      ctra := %010_111 << 23 + Pin  ' PLL single ended, PLL divide-by 1.  Note the % (!)
    
      frqa := $1999_9999                 ' 8MHz into PLL, PLL multiplies by 16 -> 128MHz out (maximum PLL rating)
      repeat  
    

    Though I can get upto at least 140MHz by increasing the FRQ value

    This of course raises a question, can a pin toggle that fast or will it burn up at some designated threshold?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-07 05:02
    Forgive if I seemed overbearing. I seem to take the point of view of what the novice Propeller user needs to know. Speed is attractive, but aside from a few applications - color video output, SRAM storage extensions, and multi-Propeller schemes; I find myself mostly inserting delays to get the i/o to become useful.

    While there are are nano-second and sub-nano-second applications, most of them are bit beyond the average Parallax customer's comfort zone. And while having to use higher speed logic chips for support is feasible, it can get rather expensive.


    I am having difficulty finding crystals or resonators in Taiwan at less than 1Mhz unless it is a 32,780hz clock crystal. I don't want to really begin to divide a 1Mhz frequency as I suspect that uses more power than xtal alone, not less. And the whole project is made more interesting by the fact that the Propeller actually expects a 5Mhz xtal for purposes of loading the EEPROM. It seems what is required is a two crystal scheme - the 5Mhz for programming EEPROM and whatever one prefers for actual low power use. Of course, there are some low power applications that don't need any xtal, but just doing those is too easy.Regarding how slow....
  • Mark_TMark_T Posts: 1,981
    edited 2012-10-07 05:17
    Forgive if I seemed overbearing. I seem to take the point of view of what the novice Propeller user needs to know. Speed is attractive, but aside from a few applications - color video output, SRAM storage extensions, and multi-Propeller schemes; I find myself mostly inserting delays to get the i/o to become useful.

    While there are are nano-second and sub-nano-second applications, most of them are bit beyond the average Parallax customer's comfort zone. And while having to use higher speed logic chips for support is feasible, it can get rather expensive.


    I am having difficulty finding crystals or resonators in Taiwan at less than 1Mhz unless it is a 32,780hz clock crystal. I don't want to really begin to divide a 1Mhz frequency as I suspect that uses more power than xtal alone, not less. And the whole project is made more interesting by the fact that the Propeller actually expects a 5Mhz xtal for purposes of loading the EEPROM. It seems what is required is a two crystal scheme - the 5Mhz for programming EEPROM and whatever one prefers for actual low power use. Of course, there are some low power applications that don't need any xtal, but just doing those is too easy.Regarding how slow....

    Counter-intuitively it can be less power-hungry to run at faster clock speeds, so long as you sleep (ie switch to RCSLOW) whenever possible - often you will be talking to a peripheral chip when running at xtal frequencies, then powering down everything till the next external event - the faster you talk to the peripheral the less time it needs to be powered up - for the processor itself energy consumption is basically proportional to the number of instructions executed, but for a peripheral the energy consumption depends on total time powered up.

    Going against this is the time needed to restart the xtal oscillator, or the desire to have an accurate timebase. Perhaps running from a 32768 xtal signal off a RTC is the way to go for sleep time, and RCFAST for wake time? RCFAST starts up a lot faster doesn't it? Anyone tried this? And RTCs can be programmed to output 1Hz or 4k or 8k or 32k - plenty of scope for ultra-low power clocking!
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-10-07 07:14
    Humanoido wrote: »
    Using a Counter, 12.6-ns to a side.

    Not sure of the exact details, but Propforth MCS uses a counter, and runs at clock speed, and includes protocol. It is very optimized in assembler. The link continuously sends 96 bit packets, and includes error checking. The effect is that the cog on the first chip talks to the cog on the send chip, same as if the two cogs were on the same chip. We dump a byte in the queue on this end, it (and 11 of its buddies) pops out of the queue 96 bit times later (more or less). The ultimate effect is that we have as many cogs and as many pins as we want, simply by added more prop chips, as a cost a cog (master) on one chip and one cog (slave) on the next; and three I/O lines (send, receive, and clock).

    This is not an academic exercise, it is a stock extension to propforth, included in the standard hardware testbed configuration in the docs. Anybody can try it, everyone is invited to comment and improve this method in any implementation.
  • jazzedjazzed Posts: 11,803
    edited 2012-10-07 13:04
    Fast toggling is a nice utility feature, but in this case it's simply hardware. However you configure it, it's still a hardware function.

    It would be great if you can find a unique and powerful application for it.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-07 14:17
    Just thinking out loud ...

    Would you be limited to just the pin flipping that fast, or would the help of external components.. i.e. an LC tank disqualify the desired result. It's possible to setup an external LC capable of a frequency much higher than the Propeller pin would be capable of, but at the same time the propeller pin would be controlling the LC. Think of the LC as a bell, and the Propeller pin as a hammer. If you 'strike' the 'bell' at just the right interval you can create a signal that 'flips' much faster than the Propeller pin is capable of.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-08 06:48
    Just thinking out loud ... Would you be limited to just the pin flipping that fast, or would the help of external components.. i.e. an LC tank disqualify the desired result. It's possible to setup an external LC capable of a frequency much higher than the Propeller pin would be capable of, but at the same time the propeller pin would be controlling the LC. Think of the LC as a bell, and the Propeller pin as a hammer. If you 'strike' the 'bell' at just the right interval you can create a signal that 'flips' much faster than the Propeller pin is capable of.
    I'm interested. How much faster?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-08 07:24
    "I'm interested. How much faster?" - As long as the desired output frequency is a multiple (harmonic) of the lower input frequency, you could probably go to at least X10 the input frequency before requiring another multiplier stage.

    Reference:
    http://electriciantraining.tpub.com/14181/css/14181_95.htm

    The above reference is taking it's information from here:
    http://www.navymars.org/national/training/nmo_courses/NMO1/module9/14181_ch2.pdf


    One thing the article doesn't describe is that the low frequency pulse must be no wider than the width of half the period of the desired high frequency. If this can't be achieved on the low end through a micro processor, then an external one-shot pulse generator should be used. In some cases a capacitor in parallel with a resistor is enough for a one-shot as long as the charge/discharge is within a reasonable target of the desired output frequency.


    For example:

    Assume we want an output frequency of 5kHz...

    If we have an input frequency of 2.5kHz, the duty cycle of that 2.5kHz should be 25% ... or a pulse duration of 100us (<- half the period of 5kHz)

    If we have an input frequency of 1.25kHz, the duty cycle of that 1.25kHz should be 12.5% ... or a pulse duration of 100us (<- half the period of 5kHz)

    If we have an input frequency of 1kHz, the duty cycle of that 1kHz should be 10% ... or a pulse duration of 100us (<- half the period of 5kHz)
  • Clock LoopClock Loop Posts: 2,069
    edited 2012-10-08 12:16
    "I'm interested. How much faster?" - As long as the desired output frequency is a multiple (harmonic) of the lower input frequency, you could probably go to at least X10 the input frequency before requiring another multiplier stage.

    So umm at 140MHz, x2 = 280Mhz with an external LC?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-08 12:19
    I think I'd be more inclined to shoot for odd harmonics with the external LC. Square waves don't contain any even harmonics to provide consistent excitation.

    -Phil
  • Clock LoopClock Loop Posts: 2,069
    edited 2012-10-08 12:35
    Scope it out.
    a.aaa-Want-to-Sniff-Some.jpg
    600 x 378 - 25K
  • Clock LoopClock Loop Posts: 2,069
    edited 2012-10-08 13:05
    Thinking long about over clocking hardware, the thought occurred to me that vectors of higher overclock plotted along an exponential increase in precision in the vector overclock, a sort of fractal overclock, might work well.
    I haven't yet attempted this or looked into the voltage increase versus heat, with this method, but I have noticed pockets of stability in much higher overclock using JUMP vectors to specific clocks, I do this with my I7 but I have not tried to perfect the method. But I had more success just JUMPing into an overclock with proper over voltage, incrementally moving up actually seems to screw the process up. I have long suspected this is due to these kind of fractal harmonics in chip fabrication.

    This might also help in successful overclock. Bind to the fractal nature.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-08 14:04
    @Clock Loop,

    "So umm at 140MHz, x2 = 280Mhz with an external LC?" - Something like that, yes.

    For your example... 140MHz in 280MHZ out
    R1 = 110 Ohms
    C2 = 5pF
    L1 = 65nH
    C1 = 5pF (trim)

    Note: since the Propeller has an internal I/O resistance of 40 Ohms, you could eliminate the 1k resistor on the I/O and reduce R1 to 70 Ohms



    @Phil Pilgrim (PhiPi)

    "I think I'd be more inclined to shoot for odd harmonics with the external LC" - typically yes, but this technique is used for multiplying a frequency in a way that's analogous to someone pushing a swing. You don't have to push the person on every stroke, but you could do it on every other stroke, or every third stroke, etc. Yes, there is some decay the longer you wait, and depending on how much energy you apply in the swing, will determine the maximum interval that you can wait.


    Note: Circuit below simulated, not physically tested.
    FMULT.JPG
    1021 x 613 - 63K
  • RaymanRayman Posts: 14,670
    edited 2012-10-08 14:07
    That circuit reminds me a lot of what X10 uses in their wireless transmitter circuit...
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-10-08 14:12
    @Rayman,

    "That circuit reminds me a lot of what X10 uses in their wireless transmitter circuit..." - could be, it's a common topology... I didn't look though I just put something together in a simulator. R1 and C2 form a one-shot pulse when the I/O pin goes high... Diodes are there to block negative spike whe the I/O pin goes low. The rest is just like ringing a bell, the tuned LC value does the rest.
  • RaymanRayman Posts: 14,670
    edited 2012-10-08 15:14
    Actually, I guess it's different... They use a uC pin just to turn an oscillator on and off, not to double the frequency...
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-08 19:20
    So the implication is the circuit could connect to a prop pin cycling at one frequency, and double it - the toggling would now measure across the circuit's output. Up to 4X when the signal becomes too weak. If the cycle could reach 4.2E-9 second, the frequency would be 238 MHz.

    The document addresses square waves / sine waves:

    "Frequency multipliers are operated by the pulses of collector current produced by a class C amplifier. Although the collector current flows in pulses, the alternating collector voltage is sinusoidal because of the action of the tank circuit. When the output tank circuit is tuned to the required harmonic, the tank circuit acts as a filter, accepting the desired frequency and rejecting all others."
  • jmgjmg Posts: 15,173
    edited 2012-10-14 11:49
    Humanoido wrote: »
    How Fast Can You Flip a Pin? Put Code Here.
    Using a Counter, 12.6-ns to a side.

    As a variant on this, how fast can one clock a pin, without using a Counter, or using software ?

    I cannot see an obvious path, but it would be nice to have a square wave ClkOut of 10-80MHz without using valuable resource.
  • Mark_TMark_T Posts: 1,981
    edited 2012-10-14 16:27
    jmg wrote: »
    As a variant on this, how fast can one clock a pin, without using a Counter, or using software ?

    I cannot see an obvious path, but it would be nice to have a square wave ClkOut of 10-80MHz without using valuable resource.

    Well I can clock the XI and XO pins at around 5MHz fairly readily ;)
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-10-15 00:49
    If you want a reference nano or pico pulse for the Propeller chip without using the Propeller resources to generate a pulse, the Picosecond company claims a pico pulse generator with 11-ps fall time.
Sign In or Register to comment.