Adventures with Jedicut, AVR via serial port and a TB6560 board

1
Hello everyone!
First of all, I didn’t make any improvements in the topic, I just used Jerome and Martin’s work, so every credit is over there. As a lame, like me, I spent several days to figure it out how exactly this stepper-motor commanding stuff works. So I’d like to share my experience.

The board (Chinese, like everything nowdays…I’ve bought it from aliexpress.com for 43$):
See the attached picture, but there is a red version too. In the view of “Jedicut” they are the same. (maybe different pinout of the LPT port, etc.). The way it controls a motor is the following: it needs 3 types of signals: a step signal, a direction, and an enable. The signals go into the LPT port, then a SN74HC14 (in my case) IC, which is a hex inverting Schmidt-trigger. This is just because the noise of the LPT port, basically it “refreshes” the edges of the square signal (and inverting them…). When our signal is well fitted, it goes to the PC817 opto-coupler IC. This gives us the shield between the PC and noisy, high voltage part of the board. And finally, the TB6560 IC, which does the job of commanding the motors. Thanks God, we don’t need to worry about the hard part (chopper control, etc.).
Before you program or control anything, you have to check your board! These Chinese guys sometimes misses some soldering. If everything looks good, look at the TB6560 pin 7: there is a capacitor over there, measure its value. (TB6560 datasheet!) The Chinese guys like to play safe, so they used a 330pF, so the internal oscillator of TB6560 works on around 130Khz. Replace the capacitor to 100pF and you can raise the speed of your stepper motor (if you want to..)
The second part of the board check-list is the pin out. You can trust the “Chinglish” user manual came with the board or you can check every circuit yourself. I’ve done the second one, and I was right! They switched up two pins, and missed out totally one of them…finally I had my own absolutely trustable pin out.
Some words about the signals: at the first time it wasn’t clear to me, how they work, but it’s simple now: first you must enable your motor, you should “pull up” the enable pin of the motor from 0V to 5V level. From that, the TB6560 will know, that he must do something with his motor (some boards need inverted signal...We will discuss it later!) This signal must be “high” while the motor spinning (even when he must hold some torque, but in the foam cutting business we don’t care about this). When we want to spin the motor, we have to say to the TB6560 which direction we want. This will be the DIR signal. Just like the ENABLE, it can be HIGH or LOW according to the CW or CCW direction. (Doesn’t matter which is which, Jedicut can reverse it at the final setup!) And finally the STEP signal. This must be a square wave signal. Every square (actually the falling edge of it…or the rising? I’m not sure..) means one step for the motor. If it is in half-step mode, a square means a half step, and so on. So, if you want your motor to spin smoothly, you must give him the right square wave (even in the frequency and the pulse width!) With Jedicut, you don’t need to worry about the pulse width, but you must setup Jedicut properly, to reach the correct spinning.
To do this, know you stepper motor, check the datasheet of it! For example, I have Longs Motor (this is Chinese too, of course!) 23HS6620 type motors. The datasheet says, it’s a 1.8deg/step motor, which means a full round will take 200 steps. I have an M6 main spindle, so a full round gives me 1mm of movement with my CNC. This gives us the first setup parameter in Jedicut: the “mm/step”. If 200 steps take 1 mm, than 1 step means 0,005mm/step. But only if we are in full step mode!!!! In half-step mode a full round needs 400steps, so the parameter will be 0,0025mm/step, and so on with 1/4 , 1/8 stepping modes. The setup of your board and the Jedicut setup must be the same for the correct “spinning”. The second part, the stepping frequency. I couldn’t find any word in the “Chinglish” motor-datasheet about the useable stepping frequencies, but my experience, that 500-800Hz is ok. Because I use the USBserial.dll for communication (later…) the “cutting speed” parameter will define the frequency of the steps in the next way: there is a timer in the AVR processor, which is counting from 0 to 255 in every 0,004 seconds (so the base frequency is 250Hz). Every time you stop this counter, it will give us a “square” wave aka. one step of the motor. So if you set up in Jedicut 64 as a cutting speed, your counter never will count until 255, just to 64 a starts counting again. So the frequency will be 1kHz now. Theoretically. Because in Martins’s code it is declared, that if you write 0 into the “cutting speed” parameter, that will be 1kHz (the highest teachable frequency) and if you write 127 (500Hz – the lowest). Any higher parameter is irrelevant, because the software will lower it to 127. Change this “cutting speed” to match your CNC, do some experiment!

USBserial.dll
At the first time, I tried the standard CNCnet_xp_vista_7.dll via LPT of course, but under WIN7/64bit I couldn’t manage it. After that I moved Jedicut to an old WIN XP laptop but good old Bill Gates crossed me over again. Timing issues, lost steps, everything sucks. And finally (after reading through the whole aeropassion.net forums) Arduino gave a solution. And Martin. Thanks again! The only problem was, that I haven’t had any arduino in my desk, only ATmega328 processors and MAX232 ICs, so (with a lot of hours of reading and learning) with Atmel Studio 6.1 (and Visual Micro add-on, both of are free and downloadable) I compiled a standard .HEX file (attached) which can be upload with any ISP programmer into a 328 processor. The MAX232 is a serial-TTL level converter IC (really cheap!) and with that the 328 and the PC can talk without any problem (google max232 datasheet, use the manufacturer given circuit!). The only modifications were that I reducied the port speed (lack of MAX232 capabilities) to 38400 baud (remember to modify it both in the PC hardware port speed, and comport.ini – in the Jedicut folder) and an additional led on PC0 (connect it with a 330Ohm resistor) to show me in order that the circuit is “alive”.
Now the fun part comes: I didn’t have to bother Jerome to “please invert the enable signal…” or “please swap the LPT port number to something…” because everything can be modified by myself in the arduino code exactly as I need! I could forget timing issues, missing steps…every annoying and disturbing Windows stuff.

I hope I could help to understand some questions to anybody who’s just learning this stuff like me.
Next time I will try to recycle Martin’s Arduino code, and replace it with pure C language to be able to use it some more advanced AVRs with more eeprom, more opportunities.

Or skip it, cut a new wing for my plane with my shiny CNC and go for flying!
Fichiers joints
TB6560 board.jpg TB6560 board.jpg Vu 3424 fois 109.67 Kio
`); }); })(jQuery, window, document, phpbb);