CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > Visual Basic


Visual Basic Discuss Visual Basic programing.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 01-28-2005, 12:26 AM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road
Visual Basic Controller - pulse width?

Hi all,

I've been playing around with creating controller software in Visual Basic. I've had good luck in creating a Jog controller that works. I can get all the motors to spin in the correct direction, however not very fast. I've played around with several different timers from milliseconds to microseconds, to nanoseconds, but I can't seem to get the same speed that other controller softwares are getting. The dll I'm using is the same one that KCam is using for interfacing the parallel port. Does anyone have a good idea what the pulse width should be between steps? I'm betting that it has something to do with this, but haven't had much luck.

Thanks,

Darren
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 01-28-2005, 04:09 AM
RotarySMP's Avatar  
Join Date: Mar 2004
Location: Vienna, Austria
Posts: 1,048
RotarySMP is on a distinguished road

KellyCAM is the worst pulse train generator I have tried, so using their DLL is probably not a great place to start. There is a reason many G code interpretors are still running on DOS, and that Art went great length to get control of XP for his Mach2.

Sorry.
__________________
Regards,
Mark
www.wrathall.com
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 01-28-2005, 08:46 AM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road

Originally Posted by RotarySMP
KellyCAM is the worst pulse train generator I have tried, so using their DLL is probably not a great place to start. There is a reason many G code interpretors are still running on DOS, and that Art went great length to get control of XP for his Mach2.

Sorry.
I realize that it is not the best option, but I'm using this as a learning experience to "enhance" upon. I'd still like to find out what I'm doing wrong. KCam can move the motors about 5 ipm, where I can only get a 1/10th of an inch if that.

Thanks for the feedback anyway.

Darren
Tweet this Post!Share on Facebook
Reply With Quote

  #4  
Old 01-28-2005, 09:00 AM
Rekd's Avatar
Community Moderator
 
Join Date: Apr 2003
Location: teh Debug Window
Posts: 1,877
Rekd is on a distinguished road

If you need accuracy, try using GetTickCount instead of a timer control.
__________________
Matt
San Diego, Ca

___ o o o_
[l_,[_____],
l---L - □lllllll□-
( )_) ( )_)--)_)

(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 01-28-2005, 09:39 AM
Swede's Avatar  
Join Date: Dec 2003
Location: United States
Posts: 383
Swede is on a distinguished road

If you're using a DLL, then you know what you are doing with VB. There are several freeware DLL's that hardware-write to the parallel port. I used one for a CNC coil-winding machine with VB. The DLL I used is inpout.dll. Here are the declarations:

'Inp and Out declarations for direct port I/O in 32-bit Visual Basic programs.
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

This DLL is well-behaved and used quite a bit by VB guys.

Swede
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 01-28-2005, 10:12 AM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road

Originally Posted by Swede
If you're using a DLL, then you know what you are doing with VB. There are several freeware DLL's that hardware-write to the parallel port. I used one for a CNC coil-winding machine with VB. The DLL I used is inpout.dll. Here are the declarations:

'Inp and Out declarations for direct port I/O in 32-bit Visual Basic programs.
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

This DLL is well-behaved and used quite a bit by VB guys.

Swede
This is actually the one that I'm using. Perhaps I'm doing it wrong? I'm using a time delay (about 6 microseconds using CreateWaitableTimer) between Out commands as a slight pause. when the commands were sent on after another without the pause I wasn't getting movement.

Thank you for your input...

Darren
Tweet this Post!Share on Facebook
Reply With Quote

  #7   Ban this user!
Old 01-28-2005, 12:28 PM
Swede's Avatar  
Join Date: Dec 2003
Location: United States
Posts: 383
Swede is on a distinguished road

Hi Darren, it's been a long time since I worked on the code for my Coil Winding machine. So if I ask stupid questions, it's definitely me!

Are you actually getting 6 microseconds, or did you mean milliseconds? 6 uS is very quick, 6mS is more typical of a VB timer control.

I remember distinctly attempting to use the timer control, which for me was a total bust. Ultimately, to control speed, I went with iterative loops which did nothing except burn CPU time between output writes to the port. The BIG problem with that is there is no simple way, when moved to another PC, to obtain exactly the same speeds, it was a matter of trial and error. Further, the operating system would hang when in the loops. My program was never designed for advanced motion control, so I did not need to interpret G-code or do anything beyond electronic gearing, which it did very nicely, thus I did not have to really push the envelope in the code development phase.

I remember one of the hardest parts of my code was in creating a smooth and gentle ramping, as the ultra-fine copper wire would break if I simply turned the motors on with a sudden pulse stream.

I'm using Flashcut as a CNC control, and while Window's-based, they use a chip in what they call a signal generator, and feed the signal generator a serial stream of data. This avoids all of the horrible timing issues inherent in Window's software.

I would recomend that you have distinct functions which can be called, with each call producing one step of the motor. Thus you can insert that call into a loop, with whatever needed delay as a part of the loop.

Sorry I couldn't be more helpful; I don't think there is any kind of magic wand one can use to avoid Windows timing problems.
Tweet this Post!Share on Facebook
Reply With Quote

  #8   Ban this user!
Old 01-28-2005, 01:47 PM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road

Originally Posted by Swede
Are you actually getting 6 microseconds, or did you mean milliseconds? 6 uS is very quick, 6mS is more typical of a VB timer control.
Swede,

I actually am not using the timer control but the CreateWaitableTimer of the kernal32.dll. You can code to microseconds using it.

I appreciate your advice and sharing your experience....Thank You.

Darren
Tweet this Post!Share on Facebook
Reply With Quote

  #9   Ban this user!
Old 01-30-2005, 06:44 PM
Swede's Avatar  
Join Date: Dec 2003
Location: United States
Posts: 383
Swede is on a distinguished road

Hi again Darren,

I never had any problem with the motors going too slow! There may be hardware differences between our setups. The little CNC machine I made used two 200 step 5.25" floppy drive motors in an electronic gearing configuration. Each motor used a "Ramsey" hobby-kit stepper motor board, capable of 500mA. I don't remember the chip, but to get the motor to move required two things - first, the chip's ENABLE line was taken high and left there. The chip then had more logic options - one line was half/full step; another was CW/CCW. Finally, to actually make the motor take a step, I took a CLOCK line high, then low. The act of toggling the clock line actuated the chip and thus the stepper.

It seemed that the chip was quite fast... I did not have to "hold" the CLOCK high for any length of time, simply cycling the clock high/low did the trick.

'Where bit 4 is the clock
'Take CLOCK high:
Result = Out (Addr, 1111 0000)

'Take CLOCK Low:
Result = Out (Addr, 1110 0000)

These two lines back to back would step the motor. I was using VB6, compiled, not interpreted. The speed of the motor was regulated then by whatever software delays I created between CLOCK pulses. I found to my irritation that a standard timer control was too slow, and without using the Win32 API, just wanting to get the project done, I executed a nested FOR:NEXT loop, varying the duration of the loop. This worked great on an old Pentium 2 computer. Of course, when I moved the software to a 2.6 gig P4, the motors screamed and lost steps!

I rewrote the code, using handy CONSTs to better time the system. It ultimately worked out OK.

You sound like a fairly advanced VB guy... if you haven't done so already, I would recommend creating a TYPE variable, something like so:

Type MotorVar
Name As String * 32 'User Definable name
PosAbsolute As Long 'Absolute Motor Position
PosRelative As Long 'Relative Motor Position
Target As Long 'Target Position
StepType As Long 'Half or full step
Direction As Long 'FORWARD or REVERSE
Delay As Long 'Looping Delay for motor
Slope As Long 'Ramp, higher = slower
SlopeReg As Long 'Temp math register
BitPattern(0 To 1) As Integer 'Value written to PortAddr
End Type

It makes dealing with the motors MUCH easier overall.

This has been a lengthy post... I don't know if I've been much help. If you'd like, PM me and I will send you the whole project, saved for VB6. The code is well commented and decently structured. There may be some tidbits that might be of use, especially the ramping aspects which were pretty tough.

Again, Good luck!

Swede
Tweet this Post!Share on Facebook
Reply With Quote

  #10   Ban this user!
Old 01-30-2005, 10:49 PM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road

Swede,
Thank you for the feedback and info. I did code using variables as well as an INI file. I found I had an optimization issue in my code and with the CreateWaitableTimer am now getting about 4.5 ipm. I did recode again using a for/next loop and was able to get about 26 ipm, but it did skip a few steps. My table is using all-thread with delrin nuts so I have a hard time getting over 10 ipm with the 80 oz/in. motors, so it is plenty fast for my needs. I have moved on to coding a g-code interpreter. I'm using some dxf source code that I found at http://home.datacomm.ch/reto.knaak/dxf.html, which was a big break. I'll post the source code once I get a little further along. Attached is a screen shot.

Thanks again,

Darren
Attached Thumbnails
Click image for larger version

Name:	wincncsm.jpg‎
Views:	6739
Size:	70.7 KB
ID:	5010  
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 02-01-2005, 11:30 PM
 
Join Date: Nov 2004
Location: usa
Posts: 49
dwwright is on a distinguished road
joystick added

I added code tonight to jog using a joystick. I'm currently using a joystick to keyboard mapping utility for KCam. I thought it would be nice to incorporate one in to my program. Also programming a couple of buttons to set the zero axis so I can set the machine without walking back to the computer to click the buttons. I also started coding the gcode interpreter.

Darren
Tweet this Post!Share on Facebook
Reply With Quote

  #12   Ban this user!
Old 02-02-2005, 10:15 AM
Swede's Avatar  
Join Date: Dec 2003
Location: United States
Posts: 383
Swede is on a distinguished road

Very nice Darren. I've been tempted to explore the use of VB to make some custom apps for my Logosol system, which uses serial commands. Logosol kindly provides VB source code and some examples as well. A full-blown g-code interpreter is quite a project.

Have you considered a PIC or similar chip? One could program the PIC to act as an offboard buffer. Feed the PIC commands from your VB interpreter via RS232. The PIC could stack them and process them, and ultimately you'd never have to deal with Windows timing issues again as the PIC would time the commands.
Tweet this Post!Share on Facebook
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Controller Project dwwright Visual Basic 29 02-14-2011 02:24 PM
Taig Mill, US Digital MS23, Controller??? marjamar Taig Mills & Lathes 3 02-07-2007 10:16 AM
Open Source CNC Controller Specification gregmary DIY-CNC Router Table Machines 28 12-04-2005 10:58 PM
New Visual Basic forum CNCadmin Visual Basic 1 02-27-2005 08:36 PM
Some basic controller questions Mwilhelm10 General Electronics Discussion 1 10-09-2003 01:45 PM




All times are GMT -5. The time now is 08:49 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353