Lightweight TCP or UDP stack for 16-bit PIC? - Page 1
Forum section: electronics / projects

author: poorchava
author_rank: Super Contributor
timestamp: September 06, 2012, 09:06:49 am
content: Hello there,I'm doing some early research for my new project, which would be a CNC driver connected via ethernet.General motivation is that I want to switch my machine to some other communication interface than LPT printer port. Most commonly used scheme for hobby/budget cnc systems is performing all the math operations (eg. calculating pulse trains for for circular and linear movement interpolation) on PC and then sensind pulse trains via Parallel port. 2 Kinds of software are generally used: Windoze based Mach 3 from Artsoft (commercial with very limited free trial) or EMC2 for Linux (now separate distro called CNCLinux). There are numerous problems with that: first of all most modern PCs and all of the laptops don't have LPT anymore, so you have to resort to PCI expansion cards or buy a designated old pc for the sole purpose of running the cnc. Old pc's are very cheap, but they take up valuable space which many of the hobbyists do not have. Second problem, especially on Windoze is that there is significant jitter in LPT port signals. If operating systems chooses to do something in the middle of you cnc operation it may miss steps or cut a stair-like shape instead of straight line at some angle. Moreover sudden OS crash can cause a little disaster (example: screen-saver turned on, pulses didn't cease when they should -> ruined workpiece, broken tool for $10, ripped motor coupling and crooked motor mount - good thing that drive nut wasn't sheared).There are of course other options for comms interface: serial, USB, and ethernet. The problem is that CNC needs real time and well synchronized pulse trains and classic step/dir interface is parallel in it's nature. So any serial approach would have to have at least some logic on the machine side, at least a serial->parallel fifo buffer with underflow prevention mechanisms. Now COM interface is a bit outdated and - same as lpt - often needs expansion cards or usb dongles because modern machines don't have it. USB on the other hand is a very nice interface with potantially high speed, but coding on both MCU and PC side is a horror. Plus the problem, that USB in itself is very hard/expensive to isolate, and galvanic isolation is mandatory.Ethernet is nice because every computer has such port, and you can connect it very easily. It also offers very high bandwidth and ihnerent galvanic isolation (magnetics).Now the main idea: i want to use Microchip's ENC28J60 ethernet transceiver (or some of their mcu with onboard ethernet transceiver). G-code file would be transferred to the device via ethernet and whole interpolation would be done in microcontroller. I see two problems: for one Microchip's open source TCP/IP stack is VERY big (they quote minimal code footprint for functional implementation at around 24-28kB) and it requires mcu program to call some ethernet handling procedures in every pass of the main loop. apparently ethernet requires some periodic activity in order to maintain connection. The problem is that any interruption in the pulse trains sent to stepper drivers will ruin the whole purpose of the device. So came the idea to use some microchip mcu for ethernet interface and pulse train calculation and then send those pulse trains into some programmable logic (rather cpld than fpga i think) with FIFO buffer implemented.Do you know of any lightweight tcp/ip stack (like <10kB of code?) which would operate in background and allow true-real-time operation of the main task? Of course i could write that myself, but i'm not that familiar with ethernet protocol and it would for sure take a very long time to develop reliable stack.Any ideas or experiences you would like to share?

author: firewalker
author_rank: Super Contributor
timestamp: September 06, 2012, 09:15:06 am
content: I know there is uIP for 8 and 16 bit micros. I think there is a port for PICs.http://en.wikipedia.org/wiki/UIP_%28micro_IP%29You can also find sample code onhttp://tuxgraphics.org/electronics/.Alexander.

author: GeoffS
author_rank: Unknown
timestamp: September 06, 2012, 09:53:46 am
content: Quote from: poorchava on September 06, 2012, 09:06:49 amHave you seen theSmoothstepper? It's available in both USB and Ethernet versions. Supported by Mach II, not sure about LinuxCNC

author: poorchava
author_rank: Super Contributor
timestamp: September 06, 2012, 10:59:39 am
content: I've seen it, but price is very high in my opinion. I understand that the guy wants to make money on it, but he's overpricing that at least x2. Smoothstepper is really a pcb with mcu, ethernet interface, some i/o drivers and screw terminals. I think whole hardware doesn't cost more than ~30-40 to make. I don't say that he's not allowed to do so, because he is. I'm just not going to buy it for that price. Maybe it's cheap-as-hell for people from US or western EU but certainly not for me.Tuxcnc website is nice, i wonder if they offer the source code (can't tell since i have no way to unpack tar.gz at work)

author: GeoffS
author_rank: Unknown
timestamp: September 06, 2012, 11:10:07 am
content: Quote from: poorchava on September 06, 2012, 10:59:39 amDo you mean LinuxCNC (used to be EMC2)? It's certainly free and the source code is available.Best option is to download the ready built distribution. It's not as easy to set up as Mach 3 but does work well.I've been using Mach 3 but will dual boot the system to give LinuxCNC a try.

author: kinsa
author_rank: Newbie
timestamp: September 24, 2012, 08:27:14 am
content: Take a look atRT-8p8c. I'm using UIP for the UDP stack.

author: kripton2035
author_rank: Super Contributor
timestamp: September 24, 2012, 08:45:41 am
content: why dont you try mikroelectronica mikro c or basic ?they have ready built in ethernet proceduresnever tried myself, but I have some similar project and will surely use their software.regards,

author: daedalus
author_rank: Regular Contributor
timestamp: September 25, 2012, 08:46:32 am
content: If you want to do motion control over Ethernet, you might want to check out EtherCAT, its an 'open' standard allegedly, and there is already Linux packages for communicating to it. There are ICs that implement all the slave handling, or you could roll your own implementation I guess.

author: westfw
author_rank: Super Contributor
timestamp: September 25, 2012, 10:24:22 pm
content: QuoteUm, and so is TCP/IP, as you are discovering. You were just hoping that someone else had already done the horrible parts for you. Which is equally likely to be true of USB. (though the galvanic isolation is still a problem.)30K *is* small for a TCP/IP/Ethernet stack. And very few such stacks are very deterministic in their timing. (Ethernet itself being non-deterministic, and most networking protocols like TCP requiting periodic servicing.) I'd suggest that you should move your "hard real-time" (step/direction pulsing) out of the "main task" and into an ISR or separate hardware so that it is easier to ensure that deadlines are met.Note that "deterministic" real time and "fast" are frequently in conflict with each other. I have "fond" memories of a BBN press release about their "new internet routing technology" that could guarantee switching of a packet in less than 1ms. I was extremely unimpressed - we were switching packets more than 10x faster than that at the time. And then there was CP's thesis on router delays and their randomness, and I realized that GUARANTEEING 1ms switching time was something we weren't even close to, and that it was really hard, even if our normal switching times were much faster.

author: poorchava
author_rank: Super Contributor
timestamp: September 26, 2012, 03:53:42 pm
content: It's true. If I achieve output frequency of 200-300kHz It will be totally satisfying, as this seems to be borderline value for most driver circuits. Plus the fact, that even at 1/64 step division on a standard 200 step/rev motor 200kHz signal translates to over 15 revs per second or almost 1k rpm. That's probably much more than any hobbyist will ever need or be able to make use of.Ethernet is much more friendly to fork with on PC side than USB is. I'm thinking about using some chip with hardware/rom ethernet stack. Something like W5100 from WizNET. It comes for like $3.5in bulk and about $5-6 singles. Seems like a promising choice and doesn't cost that much.Any opinions on that chip or other similar products?