I need to read CAN messages from a Haltech ECU, which has a 1 Mbit baud rate. I would like to then use the CAN data to control an air core motor, in this case for a speedometer. I'm struggling with what the best board, chip, and hardware setup is.
What is the maximum baud rate for the M4 CAN Express? it seems like 1Mbit requires a 16 Mhz crystal, although I don't see any crystal at all on the board.
Feather M4 CAN Express Max Baud Rate
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- DJDevon3
- Posts: 210
- Joined: Wed Mar 06, 2019 11:02 am
Re: Feather M4 CAN Express Max Baud Rate
32.768 KHz crystal for clock generation, listed on the product page. the oscillator is built into the ATSAME51J19 chip. ;)
as for baud rate, it's based on a baud-rate generator depending on clock frequency. you can read about it in the datasheet. specifically the "Clock Generation – Baud-Rate Generator" formula which is way over my head.
from what I can tell reading the datasheet it's about 64000 and will default to the lowest common denominator that doesn't produce errors, but don't quote me on that. that could just be a sample size example.
as for baud rate, it's based on a baud-rate generator depending on clock frequency. you can read about it in the datasheet. specifically the "Clock Generation – Baud-Rate Generator" formula which is way over my head.
from what I can tell reading the datasheet it's about 64000 and will default to the lowest common denominator that doesn't produce errors, but don't quote me on that. that could just be a sample size example.
- westfw
- Posts: 2008
- Joined: Fri Apr 27, 2007 1:01 pm
Re: Feather M4 CAN Express Max Baud Rate
I would think that the samd51 would have no trouble supporting 1MBps…
- westfw
- Posts: 2008
- Joined: Fri Apr 27, 2007 1:01 pm
Re: Feather M4 CAN Express Max Baud Rate
I was curious, and looked into some more of the details:
- The M4 CAN Express has a 32kHz crystal, but it's multiplied internally (with a PLL) to yield a processor clock of 120MHz.
- The SAME51 has a bunch of other clocks that it derives. The CAN controller is clocked from GCLK1, which is 48MHz. (IIRC, the chip has TWO PLLs, and one is used for the processor clock, and one for many IO devices (USB, CAN) that want a lower frequency.)
- The "Baud Rate Generator" mentioned by Dan91 is "SerCom" thing, which CAN doesn't use.
- The CAN bitrate is more complicated. BUT, the libraries make it easy to use - just put the desired bitRate in the .begin() call.
- The datasheet says that the CAN registers default to values that make a 500kHz bitrate with an 8MHz GCLK, and that the max GCLK is ~90MHz. So 1MHz with a 48MHz GCLK is well within specs.
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Feather M4 CAN Express Max Baud Rate
The microcontroller uses the 32,768 crystal to 'discipline' the PLL.
A PLL (Phase-Locked Loop) combines a varable-frequency oscillator (VFO) with a phase detector: basically a capacitor that charges for one half of a clock cycle and discharges for the other half. The PLL's control circuit adjusts the VFO frequency to keep the phase detector's output voltage constant. As a side effect, the VFO ends up matching (locking to) the input frequency.
The microcontroller's PLL extends that idea by running the VFO's output through a prescaler that ticks once for every N ticks of the VFO. Comparing that scaled-down frequency to the 32,768Hz crystal oscillator constantly adjusts the VFO frequency (96MHz to 200MHz) to remain in sync with the crystal frequency. As a result, the PLL keeps its VFO as stable as a crystal oscillator. The difference is that crystal oscillators have high intrinsic stability, and the PLL tunes itself every 30-ish microseconds.
The VFO frequency is then run through another prescaler that generates the 48MHz CPU clock.
A PLL (Phase-Locked Loop) combines a varable-frequency oscillator (VFO) with a phase detector: basically a capacitor that charges for one half of a clock cycle and discharges for the other half. The PLL's control circuit adjusts the VFO frequency to keep the phase detector's output voltage constant. As a side effect, the VFO ends up matching (locking to) the input frequency.
The microcontroller's PLL extends that idea by running the VFO's output through a prescaler that ticks once for every N ticks of the VFO. Comparing that scaled-down frequency to the 32,768Hz crystal oscillator constantly adjusts the VFO frequency (96MHz to 200MHz) to remain in sync with the crystal frequency. As a result, the PLL keeps its VFO as stable as a crystal oscillator. The difference is that crystal oscillators have high intrinsic stability, and the PLL tunes itself every 30-ish microseconds.
The VFO frequency is then run through another prescaler that generates the 48MHz CPU clock.
- dan91
- Posts: 2
- Joined: Sat Jun 25, 2022 4:55 pm
Re: Feather M4 CAN Express Max Baud Rate
It sounds like this would work then. Thank you for the replies.
- XRAD
- Posts: 754
- Joined: Sat Nov 19, 2016 3:28 pm
Re: Feather M4 CAN Express Max Baud Rate
I am interested to know when it works out for you, how you wired and programmed it. I had several haltech systems (people always raved about Megasquirt but Haltech always had a sleek package..)...sometimes super frustrating to use, sometimes super easy! Good luck :)
Please be positive and constructive with your questions and comments.