Fast Clock Signal Possible?

johndk

Senior Member
I've found a few references to a 250ns clock pulse related to srlatch and comparators here: http://www.picaxeforum.co.uk/showthread.php?24179-Tutorial-on-using-SRLatch-as-a-555-timer/page2

What I'm interested in is using that signal for an external interval timer that will operate in the microsecond range. I don't believe I can get the picaxe to do that directly (working with a 28x2 at the moment), but it would be great if I could. What I have in mind is to capture that clock and use a countdown timer to give me microsecond increments.

Can someone help me out as to how I can get that clock to show up on a (any) pin? Or alternately, how I can get microsecond length pulses directly from the picaxe.

The second part of my question is dependent on the first being possible. If I run the 28x2 at the 64MHz speed with an external 16MHz resonator, how will that affect the timing of this particular signal?

Thanks in advance!

John
 

inglewoodpete

Senior Member
I'm not exactly sure what you're trying to do. You want to generate a 250nS clock signal and use a 'countdown' timer to give a 1 MHz clock signal. What is the 1uS clock required for? Are you hoping to have the PICAXE chip to perform both these functions or do you want to do these tasks with external chips?

If you run the 28X2 at 16MHz with an external resonator, then you have an immediate 250nS square wave on one end of the resonator, since the 16MHz is generated with a 4MHz resonator and a x4 PLL. You would probably have to buffer the 4MHz signal so as not to load the resonator.
 

hippy

Technical Support
Staff member
A 20X2 can generate an 8MHz square wave using PWMOUT with -

SetFreq M64
PwmOut PWM_PIN, 1, 3

So I would expect a 28X2 with 16MHz resonator and using EM64 should do the same.

I suspect a 16MHz PWM could be generated by poking the SFR registers with a period of zero and an appropriate duty. That cannot be specified with a PWMOUT command as a period of zero turns PWM off.
 

johndk

Senior Member
I'm not exactly sure what you're trying to do. You want to generate a 250nS clock signal and use a 'countdown' timer to give a 1 MHz clock signal. What is the 1uS clock required for? Are you hoping to have the PICAXE chip to perform both these functions or do you want to do these tasks with external chips?
Not exactly. I will use the countdown timer (sequence timer) to generate pulses of specific lengths in microseconds. This will not be an oscillator, but a controller which can give me anywhere from a 1 microsecond to a 100 microsecond long pulse. These pulses would be intermittent, triggered by the PA.

Yes, I could run with a 4MHz resonator, but that would mean an extra chip (buffer). And I will also prefer to run the PA at 64MHz. So yes, I could (and might) but would rather not.
 

johndk

Senior Member
Thanks hippy!

I didn't realize one could get that short a pulse out of PMW. I'm not into robotics and haven't really played with PMW. So that's good news. An 8MHz SQW would work just fine. And if I can get a 16MHz, even better. I don't understand the technique of poking the SFR registers. Is there any documentation on that? Or perhaps some sample code for me to look at.
 

johndk

Senior Member
As I'm playing with the 28x2 at 64MHz, I'm trying to find a way to time an output pin to varying microsecond long increments (ranging from 1 - 100). As noted before, my first solution was to do this externally. But is seems with all the sub microsecond ticks going on in the x2, I should be able to do that without the need for an additional chip. In my digging, I'm finding that timer3 has an internal tick at (1/resonator speed) * 4. But the specs don't tell me if this applies to the external resonator. Is it really the resonator? Or is it the chip clock speed?

Either way, I've got sub microsecond timing ticks. How can I count them to get my time delays? I think this is what hippy might have been talking about by poking the SFR registers. Which register would I need to poke to get timer3 to give me a 3 microsecond delay, for example?
 

hippy

Technical Support
Staff member
It is getting quite confusing as to what you are wanting to do; generate a continuous stream of pulses, generate individual pulses, count them, time them, create delays ( and it's not clear what you would be delaying ).

It would probably be best to explain exactly what you are wanting to do, what the big picture overview of the project is, before trying to determine how to do it or if it can be done.
 

AllyCat

Senior Member
Hi John,

Yes, you need to appreciate that ALL PICaxe instructions take hundreds of microseconds (or instruction cycles at higher clock rates) to execute, so very little can be done "on the fly". You might just be able to start a PWM output and immediately stop it again with the next instruction, but even that will require the PWM to be set with quite a high "DIV" value (16 - 64).

For "single shot" type pulses you might be able to use the Capture/Compare SFR hardware, but using the PIC(axe)s at this level is far from trivial. IMHO it really needs to be done at the assembler/machine code level, which is not (yet) possible with a PICaxe (but has been "promised" for a long time). Most designers would recommend using dedicated hardware.

Cheers, Alan.
 

johndk

Senior Member
What I'm designing is an LED controller which can flash the LEDs for very short, but measurable and repeatable durations ... in the microsecond domain. So for instance, I would set the controller to produce 10us pulses and apply them every 5ms. They I might want to change the pulse stream to generate 50us pulses every 2ms. The controller is part of a scientific investigation involving plant growth. I've got the circuitry and programming pretty well worked out for ms sized pulses. But I'm trying to push it into the us range. From AllyCat's comment, it sounds like I should stick with my original approach which is to use an programmable interval timer to use a continuous sub microsecond frequency (PWM or one generated off the external resonator with a buffer) and get my output pulse lengths by counting off groups of these sub microsecond pulses. So for PWM frequency of 4MHz I could count 4 pulses to give me a microsecond pulse with the interval timer. The PA could control the interval timer (I'm looking at an 8254, but there may be better ones) to generate the appropriate length pulses and to strobe them in at the right times.
 

hippy

Technical Support
Staff member
Thanks for the clarification.

For short microsecond-region pulses I would perhaps consider using hardware SPI output or UART output in synchronous mode. That should allow a specific number of contiguous bits to be sent with a particular bit time.

The repeat period could then probably be achieved by a more leisurely running counter/timer.

To be honest, it is probably a project more suited to a raw microcontroller which can bit-bang pulses of the required duration repeated at the desired rate than a PICAXE. You could probably implement that to be serially controlled by a PICAXE which would give you the best of both worlds; accurate timing control with ease of controlling it.
 

AllyCat

Senior Member
Hi,

I would set the controller to produce 10us pulses and apply them every 5ms. They I might want to change the pulse stream to generate 50us pulses every 2ms. .....get my output pulse lengths by counting off groups of these sub microsecond pulses.
It depends whether you really need SUB microsecond pulses or not. A PICaxe can deliver non-repetitive 10 us or 50 us pulses using PULSOUT (or PWM for repetitive pulses) without even raising its default clock speed.

It's only if you need sub-us pulses, or "arbitrarily-spaced" pulses with sub-ms periods, that the PICaxe may struggle.

Cheers, Alan.
 

johndk

Senior Member
For short microsecond-region pulses I would perhaps consider using hardware SPI output or UART output in synchronous mode. That should allow a specific number of contiguous bits to be sent with a particular bit time.
I know I'm pushing it to the limits, which is why I'm considering using an 8254 (It won't drive me nuts ... I'm already there.... But would love to know the reason for the comment. The docs don't look that bad.)

I like the idea of using SPI or synchronous UART pulses. Thanks for that idea since I do have lots of time between the sub-micro pulse modes. I'll see if I can make it work. If not, I guess I'm headed for the looney bin.
 

techElder

Well-known member
drive me nuts ... I'm already there.... But would love to know the reason
Actually, I had trouble with using an 82C54 as a counter and reading the registers through a 40X2's ports. Looks doable, but I couldn't get it to be glitch free.

If you just set it up to be a pulse generator, you will probably be OK as I didn't have any trouble writing control words.
 
Top