Results 1 to 13 of 13

Thread: Please help with the application for my CNC

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Please help with the application for my CNC

    I cleaned up the code as much as I could.

    Before I get everyone confused, please see this thread first: http://www.vbforums.com/showthread.php?t=610022

    I am new to threading when it comes to VB.NET, one of the problems is about that.

    After the program runs (it sends and receives data to & from CNC), when I click the X (form close), it just hangs, and does not close. Every time I have to click the "Stop Debugging (Shift+F5)" button.

    Now let me explain how the CNC works.

    I hope you can keep up, because it's a long read, and a little complicated.

    The computer generates RAW (compressed) data that sends to the CNC (the microcontroller).
    The motors are stepper motors, there are 400 steps for one full rotation. The microcontroller (PIC18F4550 at 48MHz) sends impulses to the motor driver, and the motor driver gives current to the windings of the motor, therefore for each impulse the motor moves one "step", and each step is 0.9°. So 360° / 0.9 = 400 steps.

    The microcontroller has 4 buffers.
    2 buffers for incomming data (where data is compressed)
    2 buffers for output data / information with each step and direction for the motors to move.
    So when data comes in, it goes into one of the "incomming" buffers, when it's done, it calls a routine that will uncompress the data and then it goes to the "output data"
    At the beginning of the routine that does the uncompression, it gives a signal to the computer to start sending more data to fill the other buffer.
    So in short, as long as there is one empty buffer, the computer can send more data to fill it up.
    The microcontroller also sends a signal when one of the "output data" buffers is done processing.
    Also about 10 times per second, the microcontroller send the X & Y & Z positions (internal counters) to the computer.

    OK, now how does the microcontroller know what to do ?
    The data is basically a 2 bit number for each axis. So the 2 bits (therefore a 0 to 4 number),
    0 means - do nothing
    1 means - move left (also enables the motor / gives power)
    2 means - move right (enables the motor)
    3 means - do nothing - BUT keep the motor enabled

    So for example, to move the motor 3 steps to the left, small pause, then 3 steps to right it sends something like this:
    000033331113333333322233330000
    It enables the motor first, then sends 1 to move to left, keeps the motor enabled, then sends 2 to move to right, keeps the motor enabled for a while then powers down the motor.

    That was for one axis only, so for all 3 axes it uses 6 bits of data (for each step)

    Originally all coordinates are calculated as 3 Integers (32 bits) for X&Y&Z, then it substracts previous point with current point, therefore giving values of -1 or 0 or 1. Where -1 is 2 (move right), 0 remains 0 (do nothing), and 1 remains 1 (move left).

    Then it gets converted to 3 bytes (where each byte is 0 or 1 or 2), finally it gets "compressed" from 3 bytes (24 bits) to 6 bits, and then this data goes to the microcontroller.

    The code for the microcontroller I wrote it in mikroC PRO. I don't expect anyone to make improvements to it, but i'm posing it for reference if anyone is interested. See the CNC_C_Code.txt file attached.

    Now before I say what other problems I have with the code, I will let you "digg in" all this information, and see where we go from here...

    Now the problem for you is... How will you run the application without a microcontroller to "talk" to ? does anyone know how to create a virtual serial port ?
    Last edited by CVMichael; Apr 11th, 2010 at 11:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width