Best device for implementing a custom serial protocol - Page 1
Forum section: electronics / general

author: Leonelf
author_rank: Contributor
timestamp: September 09, 2018, 07:04:14 pm
content: Last year I developed an inverter for a formula student car. The motors use an EnDat 2.2 absolute position encoder. Because of the time constraints I used an Altera MAX10 evaluation board with a transceiver daughterboard to implement the protocol and to act as an SSI slave to the inverter, but I don't find my solution to be very elegant so I want to re-design it properly.I used an FPGA because I found the protocol to be very hard to implement with good performance by just bitbanging or (ab-)using SPI or DMA peripherals.EnDat requires the master to clock out a command and then continue clocking. After a startbit appears, data-reception starts, the master continues to clock after the last bit + 1.I looked into different microcontrollers with certain peripherals, especially the LPC43xx series seem interesting because of their SGPIO and STIM, but they're very expensive and large. FPGAs all seem more IOs than I need, leading to an unnecessarily big footprint. CPLDs seem too small for my VHDL design.Do you have experience implementing "custom" protocols in hard- and software? Which microcontroller or FPGA can you recommend? Or are there special techniques or microcontrollers good for very fast (6MHz) bitbanging?

author: CM800
author_rank: Frequent Contributor
timestamp: September 09, 2018, 07:13:49 pm
content: It may be possible to shrink it down further, if you were to 'ignore' the CRC and hope for the best.Equally, maybe ask the motor to be supplied with a different encoder feedback? E.g. Halls & Incremental encoder (easy to feed back to an MCU without extra hardware) or SSI, which can be used with Serial easily.What about the Lattice FPGAs like theICEStorm Compatible ones.

author: Leonelf
author_rank: Contributor
timestamp: September 09, 2018, 07:27:34 pm
content: Ordering the motors with more usable encoders is apparently impossible. Why especially the FPGAs compatible with IceStorm? Is the original Lattice software so bad?

author: CM800
author_rank: Frequent Contributor
timestamp: September 09, 2018, 08:25:05 pm
content: Quote from: Leonelf on September 09, 2018, 07:27:34 pmIcestorm actually compiles a lot faster then Lattice.Easy to use too.plus, open source is always a nice bonus

author: NorthGuy
author_rank: Super Contributor
timestamp: September 09, 2018, 08:56:12 pm
content: When you are on the master side, bit-banging is easy and doesn't need much. You just unroll the loop for the entire transmission and then you only need 2-4 instructions per bit. Which means you can easily do about 2 MHz with PIC16. If you want faster, you need something which can support a faster clock, but you don't want anything with cache or other timing impediments.SPI modules will often work on 8/16/32 bit chunks, but you can always add few bit-banged bits at the beginning, or at the end. Usually, SPI will be 2-3 times faster than bit-banging on the same CPU. Probably easier too.DMA will work just as well, however small MCUs usually don't have DMA so you'll have to go bigger. DMA is the easiest way if you want to communicate with both the encoder and the inverter at the same time.Working as an SPI slave is harder for a CPU because it must adjust of the pace of the external clock. Thus bit-banging will be harder and slower. An SPI module with a buffer will work much better. An SPI module coupled with DMA will be the best.

author: splin
author_rank: Frequent Contributor
timestamp: September 10, 2018, 10:10:15 pm
content: Whoever 'designed' that appallingly Endat protocol should be thoroughly ashamed of themselves; but you have to work with what you've got...I think you should be fine with just about any ARM Cortex M0 or better with a USART and preferably DMA.On the TX side you have to turn the transmit driver off at the end of the transmission which you could do in a counter interrupt from the timer generating the clock signal.On the receive side you can deserialize/decode 32 bits at a time so not much load at 6Mb/s. Continuous Rx mode should be pretty simple but it is more problematic otherwise as you have to stop the clock when you Rx the last bit - so perhaps use an external interrupt to catch the rising edge of the start bit and modify the timer counter generating the I/f clock generator to stop on the last Rx bit. That assumes you know the length of the Rx block beforehand, otherwise you'll have to modify the counter as you decode the Rx data.Things might be a bit more complicated if the receive block is not an integer multiple of the word lengths supported by the USART (usually 7,8 and 9 bits). If not you might have to bit bang a few bits at the start or end of the block. The latter has the advantage that you can easily stop the I/f clock at the right point.Another complication is that for data rates above 2Mb/s you need to generate the Rx clock into the USART from a 2nd timer suitably phase offset from the I/f clock to deal with delay compensation. Ideally the delay compensation measuring clock will be at least 8 x data rate, so a 48MHz would be needed for a 6Mb/s data but you might get away with less depending on cable length and the amount of noise.If a 48MHz MCU proves to be a bit of a struggle, 72 or 80MHz or more parts are still very cheap at less than $2 (eg. STM32F301). If you like a challenge and you are an assembler Ninja then maybe you could get away with a 20MHz 8-bitter but perhaps not something to get your company's future on!

author: EEVblog
author_rank: Unknown
timestamp: September 10, 2018, 11:14:40 pm
content: There are now small pin count FPGA's, Lattice IIRC, have you looked into those?

author: Mr. Scram
author_rank: Super Contributor
timestamp: September 10, 2018, 11:30:04 pm
content: Maybe you want to look at Cypress PSoC devices. Even though they provide a relativaly modest amount of FPGA type fabric they all come with one or two ARM processors alongside it. You might be able to cut the HDL down by using the processor for some parts. You can use predefined modules or write your own in Verilog. If I recall correctly DMA is available too. The footprints can be quite small. Various options are available and I think they come with various analogue features as well.It could be the wrong tool for the job, but I thought I'd mention them.

author: Leonelf
author_rank: Contributor
timestamp: September 17, 2018, 12:06:47 pm
content: Quote from: EEVblog on September 10, 2018, 11:14:40 pmI looked into them once and found the software to look quite frighteningI'll look into them againEDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?

author: Mr. Scram
author_rank: Super Contributor
timestamp: September 17, 2018, 12:17:12 pm
content: Quote from: Leonelf on September 17, 2018, 12:06:47 pmI think LEs are hard to compare directly due to differences in design and comparisons therefore tend to be handwavy.

author: ogden
author_rank: Super Contributor
timestamp: September 17, 2018, 12:54:26 pm
content: Quote from: splin on September 10, 2018, 10:10:15 pmIndeed things are complicated when you use USART where you shall be using SPI. ENDAT issynchronousinterface with separate clock line. Why would you even consider to suggest USART hereOtherwise I agree - ARM microcontroller with SPI peripheral can do the job. DMA can be implemented as well - if needed. I would not even call it abusing of SPI because it is flexible I/O "standard" and seems to be ok forENDAT protocol. I may stand corrected here, but seems like ENDAT was made with SPI peripherals in mind.You can use either very small ARM microcontroller with CAN and SPI interface as "I/O helper" or try to find bigger one with as many SPI peripherals as needed. AFAIK STM32F302RE have 4xSPI. Have no info about other brands and ARM uCs'.

author: NorthGuy
author_rank: Super Contributor
timestamp: September 17, 2018, 02:23:14 pm
content: Quote from: Leonelf on September 17, 2018, 12:06:47 pmIf you want FPGA, Xilinx's Spartan-7 is now out. They start from $15.

author: Leonelf
author_rank: Contributor
timestamp: September 17, 2018, 02:58:58 pm
content: I've found the Lattice ICE5LP4K-SG48ITR to fit my design (the 2k aswell).I'll use an external SPI-Flash (36cents are nothing compared to the OTP-NVCM of the FPGA)Are there inexpensive ways to program this FPGA? The original Lattice programmer seems to be an FTDI based SPI translator so could I just use the FTDI ft232 cable with the integrated multi-protocol engine?

author: AloyseTech
author_rank: Regular Contributor
timestamp: September 18, 2018, 08:38:47 pm
content: Most of the Cortex M0+ have single cycle IO write. I’m able to toggle at 24MHz with an ultra cheap ATSAMD09 (available in tiny package). It is useful for bit banging. Maybe the cpu itself will not be sufficient for handling the whole protocol at that speed though.

author: asmi
author_rank: Super Contributor
timestamp: September 18, 2018, 09:25:40 pm
content: Quote from: Leonelf on September 17, 2018, 02:58:58 pmI used FTDI's 3.3 V MPSSE cable - just google connection diagram and make sure you actually use 3.3 V cable, or you're going to toast your FPGA.

author: Bassman59
author_rank: Super Contributor
timestamp: September 18, 2018, 11:08:45 pm
content: Quote from: NorthGuy on September 17, 2018, 02:23:14 pmLattice MachXO2 family has parts that are easily half that price. Of course, it all depends on what he actually needs.

author: Bassman59
author_rank: Super Contributor
timestamp: September 18, 2018, 11:11:30 pm
content: Quote from: ogden on September 17, 2018, 12:54:26 pmSome (most?) ARMs' USART module can be configured to do SPI. After all, the acronym is for Universal Synchronous/Asynchronous Receiver/Transmitter, and in synchronous mode it will generate the shift clock (if set up as master) or use an external shift clock (if a slave).

author: splin
author_rank: Frequent Contributor
timestamp: September 19, 2018, 01:29:37 am
content: Quote from: Bassman59 on September 18, 2018, 11:11:30 pmPrecisely; you don't need or want to use SPI for this at all - just the synchronous part of a USART. SPI is just a particular protocol that runs on top of a USRT (the synchronous part of a USART) but is not a good fit with the ENDAT protocol.

author: NorthGuy
author_rank: Super Contributor
timestamp: September 19, 2018, 02:36:36 am
content: Quote from: Bassman59 on September 18, 2018, 11:08:45 pmTrue, but the software is less frighteningYou probably can do this with $3 PIC if money is a concern.

author: ogden
author_rank: Super Contributor
timestamp: September 19, 2018, 04:46:50 am
content: Quote from: splin on September 19, 2018, 01:29:37 amI bet you are talking about serial peripheral of AVR/ArduinoOther microcontrollers are not like that. Also better improve your knowledge about SPI before you dare to say that (synchronous) USART is ok for ENDAT but SPI - not.

author: guenthert
author_rank: Frequent Contributor
timestamp: September 26, 2018, 09:23:30 am
content: Perhaps a solution has already been identified, just wanted to have mentioned (perhaps not suitable for the given use case, but I think generally for 'custom serial protocol'):1. (for modest speeds, say up to around 1Mbaud): Parallax Propeller. It has its drawbacks (one of them the need for an external I2C addressed (EEP)ROM), but it's probably the easiest to program.2. (for considerably higher speeds, but at the cost of considerable complexity): TI Sitera ARM e.g. the AM3358 (as used in Beagle Bone Black, etc.) with its two PRUs which are explicitly made for this purpose.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: September 26, 2018, 09:42:40 am
content: FYIhttp://www.ti.com/lit/ug/tidual5/tidual5.pdfis an interesting read Sitara™ AM437x.

author: Bassman59
author_rank: Super Contributor
timestamp: September 27, 2018, 12:12:46 am
content: Quote from: ogden on September 19, 2018, 04:46:50 amWe were talking specifically about ARM (see my post). The handful of ARMs I've looked at -- Cortex M3 parts from SiLabs, Atmel and NXP -- have a USART peripheral which can be configured as, among other things, SPI, either master or slave. (Some even have a simpler peripheral called SPI, just to make things more confusing.)I've never used ENDAT, nor do I know what it is.

author: ogden
author_rank: Super Contributor
timestamp: September 27, 2018, 06:45:08 am
content: Quote from: Bassman59 on September 27, 2018, 12:12:46 amThen blame them or initial poster, but not me:Quote from: splin on September 10, 2018, 10:10:15 pmSuggesting plain USART (Universal Synchronous/Asynchronous Receiver/Transmitter) when you mean either synchronous serial or SPI is much more confusing. In case you wonder why - check roots ofUSART abbreviation.