Author Topic: Best device for implementing a custom serial protocol  (Read 4730 times)

0 Members and 1 Guest are viewing this topic.

Offline LeonelfTopic starter

  • Contributor
  • Posts: 20
Best device for implementing a custom serial protocol
« on: September 09, 2018, 07:04:14 pm »
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?
 

Offline CM800

  • Frequent Contributor
  • **
  • Posts: 882
  • Country: 00
Re: Best device for implementing a custom serial protocol
« Reply #1 on: September 09, 2018, 07:13:49 pm »
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 the ICEStorm Compatible ones.
 

Offline LeonelfTopic starter

  • Contributor
  • Posts: 20
Re: Best device for implementing a custom serial protocol
« Reply #2 on: September 09, 2018, 07:27:34 pm »
Ordering the motors with more usable encoders is apparently impossible. Why especially the FPGAs compatible with IceStorm? Is the original Lattice software so bad?
 

Offline CM800

  • Frequent Contributor
  • **
  • Posts: 882
  • Country: 00
Re: Best device for implementing a custom serial protocol
« Reply #3 on: September 09, 2018, 08:25:05 pm »
Ordering the motors with more usable encoders is apparently impossible. Why especially the FPGAs compatible with IceStorm? Is the original Lattice software so bad?

Icestorm actually compiles a lot faster then Lattice.

Easy to use too.

plus, open source is always a nice bonus :)
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3138
  • Country: ca
Re: Best device for implementing a custom serial protocol
« Reply #4 on: September 09, 2018, 08:56:12 pm »
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.

 

Offline splin

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Best device for implementing a custom serial protocol
« Reply #5 on: September 10, 2018, 10:10:15 pm »
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!
 

Offline EEVblog

  • Administrator
  • *****
  • Posts: 37728
  • Country: au
    • EEVblog
Re: Best device for implementing a custom serial protocol
« Reply #6 on: September 10, 2018, 11:14:40 pm »
There are now small pin count FPGA's, Lattice IIRC, have you looked into those?
 
The following users thanked this post: Leonelf

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Best device for implementing a custom serial protocol
« Reply #7 on: September 10, 2018, 11:30:04 pm »
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.
 

Offline LeonelfTopic starter

  • Contributor
  • Posts: 20
Re: Best device for implementing a custom serial protocol
« Reply #8 on: September 17, 2018, 12:06:47 pm »
There are now small pin count FPGA's, Lattice IIRC, have you looked into those?

I looked into them once and found the software to look quite frightening  ;D I'll look into them again

EDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?
« Last Edit: September 17, 2018, 12:08:55 pm by Leonelf »
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Best device for implementing a custom serial protocol
« Reply #9 on: September 17, 2018, 12:17:12 pm »
I looked into them once and found the software to look quite frightening  ;D I'll look into them again

EDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?
I think LEs are hard to compare directly due to differences in design and comparisons therefore tend to be handwavy.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Best device for implementing a custom serial protocol
« Reply #10 on: September 17, 2018, 12:54:26 pm »
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).

Indeed things are complicated when you use USART where you shall be using SPI. ENDAT is synchronous interface with separate clock line. Why would you even consider to suggest USART here  :palm:

Otherwise 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 for ENDAT 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'.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3138
  • Country: ca
Re: Best device for implementing a custom serial protocol
« Reply #11 on: September 17, 2018, 02:23:14 pm »
There are now small pin count FPGA's, Lattice IIRC, have you looked into those?

I looked into them once and found the software to look quite frightening  ;D I'll look into them again

EDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?

If you want FPGA, Xilinx's Spartan-7 is now out. They start from $15.
 

Offline LeonelfTopic starter

  • Contributor
  • Posts: 20
Re: Best device for implementing a custom serial protocol
« Reply #12 on: September 17, 2018, 02:58:58 pm »
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?
 

Offline AloyseTech

  • Regular Contributor
  • *
  • Posts: 121
  • Country: fr
Re: Best device for implementing a custom serial protocol
« Reply #13 on: September 18, 2018, 08:38:47 pm »
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.
 

Offline asmi

  • Super Contributor
  • ***
  • Posts: 2730
  • Country: ca
Re: Best device for implementing a custom serial protocol
« Reply #14 on: September 18, 2018, 09:25:40 pm »
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?
I 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.

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Best device for implementing a custom serial protocol
« Reply #15 on: September 18, 2018, 11:08:45 pm »
There are now small pin count FPGA's, Lattice IIRC, have you looked into those?

I looked into them once and found the software to look quite frightening  ;D I'll look into them again

EDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?

If you want FPGA, Xilinx's Spartan-7 is now out. They start from $15.

Lattice MachXO2 family has parts that are easily half that price. Of course, it all depends on what he actually needs.
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Best device for implementing a custom serial protocol
« Reply #16 on: September 18, 2018, 11:11:30 pm »
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).

Indeed things are complicated when you use USART where you shall be using SPI. ENDAT is synchronous interface with separate clock line. Why would you even consider to suggest USART here  :palm:

Some (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).
 

Offline splin

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Best device for implementing a custom serial protocol
« Reply #17 on: September 19, 2018, 01:29:37 am »
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).

Indeed things are complicated when you use USART where you shall be using SPI. ENDAT is synchronous interface with separate clock line. Why would you even consider to suggest USART here  :palm:

Some (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).

Precisely; 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.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3138
  • Country: ca
Re: Best device for implementing a custom serial protocol
« Reply #18 on: September 19, 2018, 02:36:36 am »
There are now small pin count FPGA's, Lattice IIRC, have you looked into those?

I looked into them once and found the software to look quite frightening  ;D I'll look into them again

EDIT: Going by LE-count, the Lattice iCE FPGAs seem pretty expensive to a simple MAX10, do they have special features I missed?

If you want FPGA, Xilinx's Spartan-7 is now out. They start from $15.

Lattice MachXO2 family has parts that are easily half that price. Of course, it all depends on what he actually needs.

True, but the software is less frightening :)

You probably can do this with $3 PIC if money is a concern.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Best device for implementing a custom serial protocol
« Reply #19 on: September 19, 2018, 04:46:50 am »
SPI is just a particular protocol that runs on top of a USRT (the synchronous part of a USART)

I bet you are talking about serial peripheral of AVR/Arduino :D Other 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.
 

Offline guenthert

  • Frequent Contributor
  • **
  • Posts: 712
  • Country: de
Re: Best device for implementing a custom serial protocol
« Reply #20 on: September 26, 2018, 09:23:30 am »
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.
« Last Edit: September 26, 2018, 09:25:47 am by guenthert »
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Best device for implementing a custom serial protocol
« Reply #21 on: September 26, 2018, 09:42:40 am »
FYI http://www.ti.com/lit/ug/tidual5/tidual5.pdf is an interesting read Sitara™ AM437x.
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Best device for implementing a custom serial protocol
« Reply #22 on: September 27, 2018, 12:12:46 am »
SPI is just a particular protocol that runs on top of a USRT (the synchronous part of a USART)

I bet you are talking about serial peripheral of AVR/Arduino :D Other 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.

We 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.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Best device for implementing a custom serial protocol
« Reply #23 on: September 27, 2018, 06:45:08 am »
Atmel and NXP -- have a USART peripheral which can be configured as, among other things, SPI, either master or slave

Then blame them or initial poster, but not me:

I think you should be fine with just about any ARM Cortex M0 or better with a USART and preferably DMA.

Suggesting 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 of USART abbreviation.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf