10...20 KHz interrupt needed
10...20 KHz interrupt needed
Hi to all,
I need a fixed (to control the steppers and DC motors) 10 to 20 kHz interrupt
(10.000 ... 20.000 Hz)
With the ElapsedMillisecond() command I only have msec. = 1.000 Hz
Is there a other command for a fixed interrupt,
or a work around ?
Thanks,
Marc
I need a fixed (to control the steppers and DC motors) 10 to 20 kHz interrupt
(10.000 ... 20.000 Hz)
With the ElapsedMillisecond() command I only have msec. = 1.000 Hz
Is there a other command for a fixed interrupt,
or a work around ?
Thanks,
Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: 10...20 KHz interrupt needed
This isn't 100% accurate, but it's pretty close (less than half of one percent error margin). The window receives a #INTERRUPT message approx. 10k times per second:
Code: Select all
#INTERRUPT = #WM_APP + 1
#NEWSECOND = #WM_APP + 2
Procedure kHz_Interrupt(kHz)
Protected t.q, lastt.q
QueryPerformanceFrequency_(@maxfreq.q)
maxfreq/(1000*kHz)
Repeat
QueryPerformanceCounter_(@t)
t/maxfreq
If t<> lastt
lastt=t
PostMessage_(WindowID(0), #INTERRUPT, 0, 0)
EndIf
ForEver
EndProcedure
Procedure Timer(uID, uMsg, dwUser, dw1, dw2)
PostMessage_(WindowID(0), #NEWSECOND, 0, 0)
EndProcedure
OpenWindow(0,0,0,320,200,"Interrupt",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(0, 10,70, 90,20, "Total Interrupts:")
StringGadget(1,100,70,180,20,"", #PB_String_ReadOnly)
TextGadget(2, 10,100, 90,20, "Total Seconds:")
StringGadget(3,100,100,180,20,"", #PB_String_ReadOnly)
CreateThread(@kHz_Interrupt(), 10) ; 10 kHz interrupt, pass 20 for 20kHz
tID = timeSetEvent_(1000, 0, @Timer(), 0, #TIME_PERIODIC)
seconds=0
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #INTERRUPT
icount+1
Case #NEWSECOND
seconds+1
SetGadgetText(1, Str(icount))
SetGadgetText(3, Str(seconds))
EndSelect
Until EventID = #PB_Event_CloseWindow
timeKillEvent_(tID)
BERESHEIT
Re: 10...20 KHz interrupt needed
Thanks for the help,
Marc
Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...
Re: 10...20 KHz interrupt needed
BUT the thread needs excessive CPU time!netmaestro wrote:This isn't 100% accurate, but it's pretty close (less than half of one percent error margin). The window receives a #INTERRUPT message approx. 10k times per second:
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: 10...20 KHz interrupt needed
Yes, the thread is going to use one whole core of the cpu. Do you know a way that uses less? An asm instruction that could go in the loop that will relinquish a tiny slice of cpu? I tried Sleep_(0) without success.
BERESHEIT
Re: 10...20 KHz interrupt needed
which os are you using?
it's not a good idea to control a stepper-motor from windows? how should your motor run, when your program has no cpu time? i think, this will never run correctly, windows is not a realtime os.
maybe it's possible to run under linunx.
it's not a good idea to control a stepper-motor from windows? how should your motor run, when your program has no cpu time? i think, this will never run correctly, windows is not a realtime os.
maybe it's possible to run under linunx.
sorry for my bad english
Re: 10...20 KHz interrupt needed
Hier einige Infos:
==> http://www.eggheadcafe.com/software/asp ... timer.aspx
Problem: 10kHz (20kHz) entsprechen einer Periodendauer von 0,1ms (0,05ms) ... das sind: 100µs bzw. 50µs
Da Windows kein Echtzeit-Betriebssystem ist, wird es nicht möglichsein hier einen Task laufen zu lassen, der das einhält! Bedingt durch das Betriebssystemkonzept von Windows kann es da zu Abweichungen von mehreren ms kommen!
Du kannst Dir da sicher vorstellen, was mit einem Schrittmotor passiert, wenn die Impulse mit einer Ungenauigkeit von mehreren ms daherkommen.
cu, helpy
==> http://www.eggheadcafe.com/software/asp ... timer.aspx
Problem: 10kHz (20kHz) entsprechen einer Periodendauer von 0,1ms (0,05ms) ... das sind: 100µs bzw. 50µs
Da Windows kein Echtzeit-Betriebssystem ist, wird es nicht möglichsein hier einen Task laufen zu lassen, der das einhält! Bedingt durch das Betriebssystemkonzept von Windows kann es da zu Abweichungen von mehreren ms kommen!
Du kannst Dir da sicher vorstellen, was mit einem Schrittmotor passiert, wenn die Impulse mit einer Ungenauigkeit von mehreren ms daherkommen.
cu, helpy
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: 10...20 KHz interrupt needed
Another approach is perhaps to use the clock of p.e. a soundcard. I am thinking about ASIO and the new Vista/Win7 audio subsystem.
Re: 10...20 KHz interrupt needed
UUUUUPs ... I wrote in german ... sorry 
Here the translation
A link with some informations:
==> http://www.eggheadcafe.com/software/asp ... timer.aspx (german link)
Problem: 10kHz (20kHz) correspond to a periodoc time of 0,1ms (0,05ms) ...
in [µs] ==> 100µs or 50µs
Windows is not an realtime operating system. Therfore it is not possible to run a task, which will keep an accuaracy of 100µs or 50µs. Due to the concept of windows itself, a tolerance of several x ms are possible.
You can imagine what will happen, if 100µs pulses with an accuaracy of ±10ms (or more) will be applied to an stepper motor.
cu, helpy

Here the translation
A link with some informations:
==> http://www.eggheadcafe.com/software/asp ... timer.aspx (german link)
Problem: 10kHz (20kHz) correspond to a periodoc time of 0,1ms (0,05ms) ...
in [µs] ==> 100µs or 50µs
Windows is not an realtime operating system. Therfore it is not possible to run a task, which will keep an accuaracy of 100µs or 50µs. Due to the concept of windows itself, a tolerance of several x ms are possible.
You can imagine what will happen, if 100µs pulses with an accuaracy of ±10ms (or more) will be applied to an stepper motor.
cu, helpy
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: 10...20 KHz interrupt needed
Why not using a USB microcontroller to control the stepper.
You then can control speed and direction just by USB commands
You then can control speed and direction just by USB commands

Re: 10...20 KHz interrupt needed
Thanks all,
@Josh
I use Win XP SP3 - AMP +3200 XP cpu at 2.2 GHz - and 1.5 GB ram
@All
I just realize that the only solution to have a stable interrupt time,
is to use a Hardware Interrupt Generator (HIG)
That is not so complicated for me to build.
But how to activate PureBasic stepper subroutine is the problem.
Via Centronics port (5 VDC) ?, RS232 port (+-12 VDC) ?, Other
@RE-A
is USB not to complicated to control (communication protocol) ?
I used in a previous project an 68000 and 68HC11 both written in Assembler.
Works fine for 2 steppers.
For my new robot I need to control 8 steppers in real time,so ...
- 2 steppers for motion control
- 4 steppers for robot arm
Some information here (sorry written in dutch)
http://www.marc-systems.be/new_2010/hob ... _deel3.htm
Is PureBasic a stand alone program after compilation or is it depending Windows ?
Marc
@Josh
I use Win XP SP3 - AMP +3200 XP cpu at 2.2 GHz - and 1.5 GB ram
@All
I just realize that the only solution to have a stable interrupt time,
is to use a Hardware Interrupt Generator (HIG)
That is not so complicated for me to build.
But how to activate PureBasic stepper subroutine is the problem.
Via Centronics port (5 VDC) ?, RS232 port (+-12 VDC) ?, Other
@RE-A
is USB not to complicated to control (communication protocol) ?
I used in a previous project an 68000 and 68HC11 both written in Assembler.
Works fine for 2 steppers.
For my new robot I need to control 8 steppers in real time,so ...
- 2 steppers for motion control
- 4 steppers for robot arm
Some information here (sorry written in dutch)
http://www.marc-systems.be/new_2010/hob ... _deel3.htm
Is PureBasic a stand alone program after compilation or is it depending Windows ?
Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...
Re: 10...20 KHz interrupt needed
It's depending on the OS you compile for, Windows, Linux or MacOS X.marc_256 wrote: Is PureBasic a stand alone program after compilation or is it depending Windows ?
For realtime control you realy should use hardware or a realmode OS like FreeDOS.
Re: 10...20 KHz interrupt needed
look here
just for information, it's not really cheap and it's intended for milling machines. but this part can handle 4 stepping motors
just for information, it's not really cheap and it's intended for milling machines. but this part can handle 4 stepping motors
sorry for my bad english
Re: 10...20 KHz interrupt needed
Marc,
You are right, USB isn't easy but lots of pc's and specially laptops doesn't have the printer or RS232 port anymore and RS232 converters are very slow in bit-bang mode.
I created a USB PIC programmer with PB for Windows and Linux using the 18F2550 microcontroller and designed my own communication protocol. You can do the same for your commands like direction, acceleration, speed, etc….
I wouldn’t recommend assembler to create the USB firmware, it’s a little to complicated for that
You are right, USB isn't easy but lots of pc's and specially laptops doesn't have the printer or RS232 port anymore and RS232 converters are very slow in bit-bang mode.
I created a USB PIC programmer with PB for Windows and Linux using the 18F2550 microcontroller and designed my own communication protocol. You can do the same for your commands like direction, acceleration, speed, etc….
I wouldn’t recommend assembler to create the USB firmware, it’s a little to complicated for that
