How Fast Can You Flip a Pin? Put Code Here.
Humanoido
Posts: 5,770
Using a Counter, 12.6-ns to a side.
[FONT=Verdana][FONT=&][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
I wonder if the generator can be used to toggle a pin faster?
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.
Much as it has been hard for me to study them, searching and sorting algorithms are important.
Though I can get upto at least 140MHz by increasing the FRQ value
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.
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.
This of course raises a question, can a pin toggle that fast or will it burn up at some designated threshold?
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!
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.
It would be great if you can find a unique and powerful application for it.
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.
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)
So umm at 140MHz, x2 = 280Mhz with an external LC?
-Phil
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.
"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.
"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.
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."
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