# Rev\_3 e-MTB front mount

**URL:** <https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244>\
**Category:** announcement\
**Created:** [October 7, 2021, 5:32pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244 "2021-10-07T17:32:04Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 9:24am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/23 "2021-11-09T09:24:57Z")

</div>

Regarding the data stream;

I have a problem with USB buffer overflowing using sFoCStudio. There is some mismatch between the serial link and the USB driver. Also while downsampling.

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 9, 2021, 9:27am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/24 "2021-11-09T09:27:57Z")

</div>

Hmmmm… that’s one for @JorgeMaker 🙂  
I’ve had SimpleFOC Studio connected to different MCUs for very long times… I think there a few issues with the way it handles data because it can get kind of laggy in some situations, but I haven’t had any issues with buffer overflows.  
What platform do you run it on?

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 9:28am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/25 "2021-11-09T09:28:59Z")

</div>

Laggy, yeah that´s the thing… Have to disconnect and then re-conect to get real time data.  
Maybe its a view setting thing. Anyways. I have noticed a disturbance in the motor when serial connected.

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 9, 2021, 9:38am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/26 "2021-11-09T09:38:33Z")

</div>

> [@Juan-Antonio\_Soren\_E](#):
>
> Anyways. I have noticed a disturbance in the motor when serial connected.

The monitoring definitely changes the speed of the FOC loop, also in my experience it has an impact on performance… but you also have to get data on what’s going on, right? Serial is a convenient way to do it… on dual core MCUs like the ESP32 and RP2040 there should be some things you can do with multithreading to optimise this.

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 9:53am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/27 "2021-11-09T09:53:58Z")

</div>

> [@runger](#):
>
> optimise this.

I believe it would help to Call the foc loop in between sending USB chars. When the receiver g’ets a new-line, that’s the end of transmission.

---

<div class="post-metadata">

**Author:** ![JorgeMaker](https://community.simplefoc.com/user_avatar/community.simplefoc.com/jorgemaker/32/546_2.png) [@JorgeMaker](https://community.simplefoc.com/u/JorgeMaker)\
**Post date:** [November 9, 2021, 1:06pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/28 "2021-11-09T13:06:17Z")

</div>

Hi @runger

I always run SimpleFOC Studio on MacOSx . Never tested for very long times

regards

---

<div class="post-metadata">

**Author:** ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)\
**Post date:** [November 9, 2021, 1:37pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/29 "2021-11-09T13:37:23Z")

</div>

> [@runger](#):
>
> share the telemetry data to the M7 core via DMA and shared memory. The M7 core can then upload the data as a USB device to a host running SimpleFOC studio… in this way it should be possible to get very high density data at no cost to the motor control loop… 😃 this is the kind of thing I dream up but never have time to implement

i know this is getting offtopic but how is this different than simply using spi with dma to read the control values sent by any external device?

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 9, 2021, 3:24pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/30 "2021-11-09T15:24:50Z")

</div>

> [@JorgeMaker](#):
>
> I always run SimpleFOC Studio on MacOSx . Never tested for very long times

Me too on OS X… I’m super-happy with it, even if it has some rough edges

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 9, 2021, 3:31pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/31 "2021-11-09T15:31:36Z")

</div>

> [@Valentine](#):
>
> i know this is getting offtopic but how is this different than simply using spi with dma to read the control values sent by any external device?

you mean like with a raspberry pi? I was thinking about getting the values to a PC (e.g. SimpleFOC Studio) - I guess the best way to measure a lot of things is with the oscilloscope and/or logic analyser, but when it comes to introspecting the calculated values within SimpleFOC you have to send them out somehow…

If you can set up DMA to SPI then you’re a long way forward on the MCU side, but you still have to interpret the SPI on the receiving side - serial (esp. via USB) is one or few steps easier to read on a Mac or PC than SPI would be.

But for sure there are many possible solutions here, depending on your MCU and preferred comms…

---

<div class="post-metadata">

**Author:** ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)\
**Post date:** [November 9, 2021, 3:59pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/32 "2021-11-09T15:59:09Z")

</div>

> [@runger](#):
>
> getting the values to a PC

Both send and receive? also on the receiving side (say Windows), why would it be a problem, since the client would be grossly overpowered, any CPU peripherals would overrun any MCU peripherals as far as data bandwidth is concerned. Do I understand the problem or I’m thinking of something else?

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 5:09pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/33 "2021-11-09T17:09:09Z")

</div>

I think there is a misconception about the SAMD51 USB peripheral. You don’t really need to set a baud rate, since its a virtual thing. SPI and USB are two distinct protocols. Its no different then sending G codes to a stepper controller. How are the commands parsed? I will assume DMA is set up with how the USB hardware works …

> [@Valentine](#):
>
> is this different than simply using spi

> **[SAMD51 - DMA for USB](https://forum.arduino.cc/t/samd51-dma-for-usb/649757)**
>
> Hi! I am having issues understanding how DMA works in the SAMD51 processor. I am converting a SAMD21 library to run with D51 chips. From my understanding after reading both the data sheets is that the whole DMA register layout changed...

In sFoCStudio, we set up the connection as it was in fact a serial connection, which it is not. It is a full speed USB connection.

[https://github.com/gdsports/USB\_Host\_Library\_SAMD](https://github.com/gdsports/USB_Host_Library_SAMD)

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 9, 2021, 5:27pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/34 "2021-11-09T17:27:06Z")

</div>

> [@Valentine](#):
>
> Both send and receive?

For the fast comms, its really just receive by the PC - at least normally I don’t think you want to command nearly as much as you want to read telemetry data. Sending a few commands, even if you do it at 500Hz, won’t take much bandwidth, and since the hardware always has a few bytes buffer it happens more or less without delays on the MCU side.

But sending data, esp. at the rate the FOC loop is (or should be) executing, is more of a challenge for the MCUs.

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 5:59pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/35 "2021-11-09T17:59:16Z")

</div>

> **[Arduino Serial Vs SerialUSB](https://hackaday.com/2021/03/20/arduino-serial-vs-serialusb/)**
>
> \[Andrew\] wonders why the SerialUSB() function on the Cortex M3-based Arduino Due is so much faster than Serial() on the Uno or Nano, and shares his observations in this short video. He sets up an e…

[![](https://img.youtube.com/vi/64qXT2zZmZM/maxresdefault.jpg "Difference between SerialUSB and Serial on Arduino DUE [Analyzing Arduino USB Packets on WireShark]") ](https://www.youtube.com/watch?v=64qXT2zZmZM)

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 9, 2021, 6:29pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/36 "2021-11-09T18:29:46Z")

</div>

![Pipe](https://community.simplefoc.com/uploads/default/original/2X/6/672c6a59e9fa575c30956e84d5a8e8277b557e8a.jpeg)

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 10, 2021, 9:08am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/38 "2021-11-10T09:08:30Z")

</div>

Ok, I see the USB message is broken down into separate chars. Each USB package has just one character. That is a lot of packages to send.

 ![capture](https://community.simplefoc.com/uploads/default/original/2X/d/da0fa899a6000527c61db4df6d303dcc625f4cbd.jpeg)

[Edit] In order to send larger messages, you have to first assemble the message from the various variables plus the right termination. You basically need a hardware specific file for simpleFoCstudio commander.

It is definitely not the connection, rather its how the commander sends out the variables.

 ![capture2](https://community.simplefoc.com/uploads/default/original/2X/9/9dc8e09c0ec8be45def881acad67e1e669ff3e9f.jpeg)

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [November 10, 2021, 10:48am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/39 "2021-11-10T10:48:46Z")

</div>

Hey, that’s actually a good find and very interesting… I assume there’s stuff you can do depending on which Serial implementation you use, and maybe with build flags, depending on architecture.  
But it doesn’t look like it would be hard to account for it in the commander code. I’ll put it on our list! 🙂

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 10, 2021, 10:54am UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/40 "2021-11-10T10:54:45Z")

</div>

```auto

char buff0[10];
char buff1[10];
char buff2[10];
char buff3[10];

   // #include <avr/dtostrf.h>

    long currentMillis = micros();
  loops++;

   if(currentMillis - lastMillis2 > 500){

   dtostrf(motor.target, 4, 4, buff0);
   dtostrf(motor.voltage.q, 4, 4, buff1);
   dtostrf(motor.shaft_velocity, 4, 4, buff2);
   dtostrf(motor.shaft_angle, 4, 4, buff3);
   
  // stringOne += "test string : ";
  // stringOne += " ";
   stringOne += (buff0);
   stringOne += " ";
   stringOne += (buff1);
   stringOne += " ";
   stringOne += (buff2);
   stringOne += " ";
   stringOne += (buff3);

   Serial.println(stringOne);
   //Serial.println("\n");
   stringOne = ""; 
   lastMillis2 = currentMillis;
// PS Be aware of RAM leaks and strings 

   }
  
   //motor.monitor();

```

 ![capture 3](https://community.simplefoc.com/uploads/default/original/2X/e/e6f68366cab0d6b2ed5cf0eed8e187a11f65b0da.jpeg)

[Edit] Updated code to use micros();

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 10, 2021, 12:05pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/41 "2021-11-10T12:05:27Z")

</div>

I can confirm, writing a string to simpleFoCStudio does not work… Cant test properly at this moment, but i can see the data coming through in one single packet.

Edit: does not work… I cant tell how sFoCStudio parses the data?

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 10, 2021, 1:22pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/42 "2021-11-10T13:22:22Z")

</div>

@JorgeMaker  
I just ran a test using the motor.monitor(); function vs. writing a string via USB to FoCStudio. Turns out the motor.monitor(); is significantly slower, compared to sending a string each 2 milliseconds. I think it has to do with the USB protocol doing excessive handshaking.

this is using motor.monitor();

 ![image](https://community.simplefoc.com/uploads/default/original/2X/5/5a54835b03834c9f010800be9004809c85886464.png)

This is sending a string each 2 millisecond’s

 ![image](https://community.simplefoc.com/uploads/default/original/2X/a/a1743f5b32068798c621c4a424664e6728132b5f.png)

---

<div class="post-metadata">

**Author:** ![Juan-Antonio\_Soren\_E](https://community.simplefoc.com/user_avatar/community.simplefoc.com/juan-antonio_soren_e/32/9969_2.png) [@Juan-Antonio\_Soren\_E](https://community.simplefoc.com/u/Juan-Antonio_Soren_E)\
**Post date:** [November 12, 2021, 1:21pm UTC](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244/43 "2021-11-12T13:21:00Z")

</div>

I see the void FOCMotor::monitor() function is not part of sFoCStudio. sFoCStudio pull´s the data when plotting the graphs. So running the motor.monitor(); while using sFoCStudio is a waste of serial bandwith?

IMO the best and fastest way, when using a MCU with a virtual USB port, is to print out the data without asking for it first, but with the possibility to change variables through commands. Using the full 64bit USB package. So there should be a command called bool stream\_data. On the receiving side, the python code will split the message using comma-seperation. This will move the main “work” to the receiving side, which typically will be much faster then the sending side (MCU).

[Previous page](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244.md?page=1)

[Next page](https://community.simplefoc.com/t/rev-3-e-mtb-front-mount/1244.md?page=3)
