Pulse burst

Hendriks

Member
I there a way to make a pulse burst?

I want to send a signal to a standard stepper motor controller that needs Step and Dir pulses.
The Dir is no problem of course, but to let the motor make fast steps I would need to output about 1000Hz to the Step input.
A do loop is not fast enough and a basic command doesn't exist (or I can't find it at least).

PWM output of any frequency works ok but I don't think I can send 5000 pulses at 1000Hz with this command.

Any ideas?
 

SAborn

Senior Member
If you dont mind running a PC then any cnc package will do exactly what you want, i use the Mach3 demo version for most cnc stuff i do, and you can drive the motor direct from the arrow keys on the keyboard if you dont want to construct some simple G-code to run it.
 

hippy

Technical Support
Staff member
This will generate a pulse burst at 1.4kHz and increasing the PAUSEUS will reduce that. 1.9kHz is achievable without a PAUSEUS and an X2 at 64MHz should be able to achieve even higher frequencies.

A DO-LOOP was almost as fast, 1.4KHz with a PAUSEUS but just 1.7kHz without. I suspect it's the SETFREQ command which you had not considered applying.

Code:
#Picaxe 20M2
SetFreq M32
Do
  Low C.0
  For w0 = 1 To 5000
    Toggle C.0
    PauseUs 1
  Next
  Pause 1000
Loop
 

hippy

Technical Support
Staff member
Having just done some serial tests and having a 20X2 in the board I tested the 20X2 at 64MHz...

Code:
#Picaxe 20X2
SetFreq M64
Do
  Low C.0
  For w0 = 1 To 5000
    Toggle C.0
    PauseUs 1
  Next
  Pause 2000
Loop
3.3kHz with the PAUSEUS, 4.0kHz without.
 

Hendriks

Member
I didn't acknowledge the SETREQ command, thanks.
It is really fast enough now.

@MartinM75 Why do you use Toggle B.0 twice in 1 loop? Is this faster?
 

Goeytex

Senior Member
Connect Pins c.3 to c.2 via a 330 ohm resistor.

This will send out a burst of exactly 500 pulses @ 1000hz

Code:
#picaxe 08m2
setfreq m32

pwmout pwmdiv64, 2, 124, 0  '1000hz @32mhz / signal off

top:
pwmduty 2, 250  'signal on
for w0 = 1 to 499   '500 pulses
pulsin c.3, 1, w1
next w0 
pwmduty 2,0   'signal off
pause 30      'dead time
goto top
 

MartinM57

Moderator
...because the experiments were about how fast pulses can be generated, not just edges, so to get 0->1->0 you need 2 Toggle B.0 commands.

If you wanted 1000 pulses I suppose you could do

for w0 = 1 to 2000
toggle B.0
next

instead of

for w0 = 1 to 1000
toggle B.0
toggle B.0
next

...but I'm sure the latter is much quicker as there's only half the number of for...next checks being done.

So even faster (inter-pulse gaps and overall elapsed time) would be:
for b0 = 1 to 100
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
toggle B.0
next

...I expect
 

Hendriks

Member
If that is correct, there should be a time difference in your scope screendump between the 2 Toggles and the next 2 Toggles, right?
 

Hendriks

Member
I tried your idea Goeytex, but it doesn't give 100% result.
Your code does generate a burst of 1kHz pulses but then I tried to count them. Just to be sure I used a second 08M2 to do the counting.
The display shows results every second varying between 479 and 498.
Code pulse burst:
Code:
#picaxe 08m2

setfreq m32

pwmout pwmdiv64, 2, 124, 0  '1000hz @32mhz / signal off

top:
pwmduty 2, 250  'signal on
for w0 = 1 to 499   '500 pulses
pulsin c.3, 1, w1
next w0 
pwmduty 2,0   'signal off
pause 8000    'dead time 1 sec.
goto top
Code Pulses Count:
Code:
#picaxe 08m2
pause 2500

Init:
	symbol LCD=C.1
	symbol BurstIn=C.2
	symbol Trigger=pinC.2

	'b0 - b4 ascii variable
	symbol NumberOfPulses=w4

	serout LCD,N2400,(254,1)

CountPulses:
	do
		if Trigger=1 then
			count BurstIn,500,NumberOfPulses	
			bintoascii NumberOfPulses,b0,b1,b2,b3,b4
			serout LCD,N2400,(254,128,b2,b3,b4)
		endif
	loop
End
Any ideas?
 

MartinM57

Moderator
If that is correct, there should be a time difference in your scope screendump between the 2 Toggles and the next 2 Toggles, right?
I only did do...loop and didn't look closely for time differences after every two toggles - I still reckon a for...next would have bigger gaps. Maybe Hippy can get his Saleae out and check...
 

Hendriks

Member
Thanks for the help.

Anyway, to send pulses with a higher frequency a command like PulseOut Time,Duty,NumberOfPulses would be a great addition:)
 
Top