Go Back  R/C Tech Forums > General Forums > Radio and Electronics
The Homebuilt Dynamometer (Dyno)Thread!!! >

The Homebuilt Dynamometer (Dyno)Thread!!!

Community
Wiki Posts
Search
Like Tree16Likes

The Homebuilt Dynamometer (Dyno)Thread!!!

Thread Tools
 
Search this Thread
 
Old 04-13-2024 | 09:57 PM
  #136  
Tech Master
iTrader: (1)
 
Joined: Jun 2007
Posts: 1,627
Default

Instead of the delay() command, you could use the millis() command. Using delay sets the arudino board to simply stop dead until the wait time is over. Millis can be used to let the board deal with other tasks while waiting. That should make your code a bit more efficient.
kufman likes this.
Sabin is offline  
Old 04-14-2024 | 10:08 AM
  #137  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by Sabin
Instead of the delay() command, you could use the millis() command. Using delay sets the arudino board to simply stop dead until the wait time is over. Millis can be used to let the board deal with other tasks while waiting. That should make your code a bit more efficient.
So construct a little loop using millis() to create the delay? Or us the modulo operator and every time it is 0, rerun the main loop?
kufman is offline  
Old 04-14-2024 | 04:28 PM
  #138  
PDR's Avatar
PDR
Tech Elite
iTrader: (31)
 
Joined: Oct 2008
Posts: 2,207
From: Sydney, Australia
Default

Originally Posted by kufman
So construct a little loop using millis() to create the delay? Or us the modulo operator and every time it is 0, rerun the main loop?
Something like this. Define a value that determines time between updates and then check each loop if that time has expired.

const int NumPortsToRead = 6;
int AnalogResult[NumPortsToRead];
volatile unsigned long TimeStamp = 0;
volatile unsigned long time1 = 0;
volatile unsigned long time2 = 0;
volatile unsigned long Oldtime1 = 0;
volatile unsigned long Oldtime2 = 0;
volatile unsigned long TempTime1 = 0;
volatile unsigned long TempTime2 = 0;
String AllResult = "";

#define UPDATE_INTERVAL 50 // Number of milliseconds between each update
unsigned long lastUpdateTime;

void setup() {
// Initialize serial communication
// Ensure that Baud rate specified here matches that selected in SimpleDyno
// Availailable Baud rates are:
// 9600, 14400, 19200, 28800, 38400, 57600, 115200
Serial.begin(115200);
// Initialize interupts (Pin2 is interrupt 0 = RPM1, Pin3 in interrupt 1 = RPM2)
attachInterrupt(0,channel1,FALLING);
// attachInterrupt(1,channel2,FALLING);

lastUpdateTime = millis();
}

void loop() {
unsigned long currentTime = millis();
if((currentTime - lastUpdateTime) > UPDATE_INTERVAL){
lastUpdateTime = currentTime;

AllResult = "";
AllResult += micros();
AllResult += ",";
AllResult += TempTime1;
AllResult += ",";
AllResult += time1;
AllResult += ",";
AllResult += TempTime2;
AllResult += ",";
AllResult += time2;
for (int Looper = 0; Looper < NumPortsToRead;Looper++){
AnalogResult[Looper] = analogRead(Looper);
AllResult += ",";
AllResult += AnalogResult[Looper];
}
Serial.println (AllResult);
Serial.flush();
}

//delay(20); //20 is default
}

//Interrupt routine for RPM1
void channel1(){
TempTime1 = micros();
time1 = TempTime1-Oldtime1;
Oldtime1 = TempTime1;

}

PS: I've got some ideas for a smarter board to give you better results.
kufman likes this.
PDR is offline  
Old 04-14-2024 | 05:56 PM
  #139  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

PS: I've got some ideas for a smarter board to give you better results.
What do you have in mind?
kufman is offline  
Old 04-14-2024 | 06:06 PM
  #140  
PDR's Avatar
PDR
Tech Elite
iTrader: (31)
 
Joined: Oct 2008
Posts: 2,207
From: Sydney, Australia
Default

Originally Posted by kufman
What do you have in mind?
Switch to a more modern microcontroller with better ADC and hardware-based timing (the micros() function with interrupts will give you less precise results). Maybe buffer data for a whole run and dump it at the end. This might be optional. At 115200, dumping 60 characters out will take nearly a quarter of your window.
Speed 8 likes this.
PDR is offline  
Old 04-14-2024 | 06:39 PM
  #141  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by PDR
Switch to a more modern microcontroller with better ADC and hardware-based timing (the micros() function with interrupts will give you less precise results). Maybe buffer data for a whole run and dump it at the end. This might be optional. At 115200, dumping 60 characters out will take nearly a quarter of your window.

Sounds like a plan. I have dumped the whole run to a bigger before and it works well. What micro do you recommend? I just bought a Minima id that is useful.
kufman is offline  
Old 04-14-2024 | 07:40 PM
  #142  
PDR's Avatar
PDR
Tech Elite
iTrader: (31)
 
Joined: Oct 2008
Posts: 2,207
From: Sydney, Australia
Default

Originally Posted by kufman
Sounds like a plan. I have dumped the whole run to a bigger before and it works well. What micro do you recommend? I just bought a Minima id that is useful.
The Minima will be quite capable. The microcontroller in that has hardware support for period measurement, but I don't have experience with it. Using it would require some non-portable code (which is fine). I'm fond of the Microchip Dx series which have pretty cool integrated peripherals. They're less powerful at computational stuff, but handle I/O really nicely. I was thinking of adding a 2MB local
kufman likes this.
PDR is offline  
Old 04-15-2024 | 11:27 AM
  #143  
trilerian's Avatar
Tech Elite
iTrader: (51)
 
Joined: Apr 2005
Posts: 2,393
From: Lexington KY
Default

Originally Posted by PDR
Switch to a more modern microcontroller with better ADC and hardware-based timing (the micros() function with interrupts will give you less precise results). Maybe buffer data for a whole run and dump it at the end. This might be optional. At 115200, dumping 60 characters out will take nearly a quarter of your window.
The ADC on the 328P is actually quite good despite the resolution. Which we both know we can oversample it pretty easily for that resolution. Generally I have found that even over sampling the 328P ADC it is faster than an I2C external, not as fast as an SPI, but hey... As to the linearity of the Renesas ra4m1, I'm not sure. I'll probably have to do a linearity test myself to know since Google is failing me.

Another thing to think about in this build. Where to measure voltage for the input. I'm actually thinking that a 4 wire setup be used and measure at the ESC as close to the internal contacts as you can. This would then eliminate the wire length as a variable, and can be achieved with a rail to rail op amp and a handful of precision resistors. There is not a dyno that I know of that uses a 4 wire measurement, so maybe it is overboard...
trilerian is offline  
Old 04-15-2024 | 11:59 AM
  #144  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by trilerian
The ADC on the 328P is actually quite good despite the resolution. Which we both know we can oversample it pretty easily for that resolution. Generally I have found that even over sampling the 328P ADC it is faster than an I2C external, not as fast as an SPI, but hey... As to the linearity of the Renesas ra4m1, I'm not sure. I'll probably have to do a linearity test myself to know since Google is failing me.

Another thing to think about in this build. Where to measure voltage for the input. I'm actually thinking that a 4 wire setup be used and measure at the ESC as close to the internal contacts as you can. This would then eliminate the wire length as a variable, and can be achieved with a rail to rail op amp and a handful of precision resistors. There is not a dyno that I know of that uses a 4 wire measurement, so maybe it is overboard...
I am currently measuring the voltage right at the connector to the ESC since it is also my current measurement board. This way, I don't have to move it with each new ESC I use. It is true that I don't account for losses in the connector and the few inches of wire that go into the ESC. I make the negative lead the common for my entire system.

I could probably bring my Minima to work and measure the analog with some of the voltage calibrators I have here. I never thought about the linearity in the past because I was always using the same ic. The ra4m1 does claim to have a higher bit resolution than the 328. Up to 14 bits I think if you configure it that way. I use analog filtering on the signals just as they enter the micro controller. Super simple, single pole, RC filters. Usually the 3db point is around 80Hz. I do terminate unused ADC channels on the Nano which reduces noise a fair amount.
kufman is offline  
Old 04-15-2024 | 02:08 PM
  #145  
trilerian's Avatar
Tech Elite
iTrader: (51)
 
Joined: Apr 2005
Posts: 2,393
From: Lexington KY
Default

Originally Posted by kufman
I am currently measuring the voltage right at the connector to the ESC since it is also my current measurement board. This way, I don't have to move it with each new ESC I use. It is true that I don't account for losses in the connector and the few inches of wire that go into the ESC. I make the negative lead the common for my entire system.

I could probably bring my Minima to work and measure the analog with some of the voltage calibrators I have here. I never thought about the linearity in the past because I was always using the same ic. The ra4m1 does claim to have a higher bit resolution than the 328. Up to 14 bits I think if you configure it that way. I use analog filtering on the signals just as they enter the micro controller. Super simple, single pole, RC filters. Usually the 3db point is around 80Hz. I do terminate unused ADC channels on the Nano which reduces noise a fair amount.
The Nano's ADC is extremely linear. As said, its resolution being 10bit isn't good, but you can oversample it. The ADC on the Nano is ~10000 samples / sec. For the Minima, I can create a simple circuit to read voltage and use bench supply to output different voltages from 0V-5V and see how the Minima reads it. I have one that I haven't really messed with. Time is not on my side though.

As to the voltage reading of the battery, what I am suggesting is to remove the voltage sense from the ground plane and measure the potential difference through a differential amplifier. You can still filter the inputs with the op-amp by creating a 2nd order filter, or you can filter the output of the op-amps with a 1st order RC filter like you are doing now. But separating the voltage sense from the ground plane allows you to measure the true voltage at the point where you are measuring it without worrying about how the current is affecting the reading. Like I said, this may be overboard for a dyno, and if you are just breadboarding this it would be difficult to achieve anyway. Speaking of, do you plan on building your own pcb and break out the mcu from the dev board at some point? If so, that is a consideration for the mcu choice.
trilerian is offline  
Old 04-15-2024 | 07:18 PM
  #146  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by trilerian
The Nano's ADC is extremely linear. As said, its resolution being 10bit isn't good, but you can oversample it. The ADC on the Nano is ~10000 samples / sec. For the Minima, I can create a simple circuit to read voltage and use bench supply to output different voltages from 0V-5V and see how the Minima reads it. I have one that I haven't really messed with. Time is not on my side though.

As to the voltage reading of the battery, what I am suggesting is to remove the voltage sense from the ground plane and measure the potential difference through a differential amplifier. You can still filter the inputs with the op-amp by creating a 2nd order filter, or you can filter the output of the op-amps with a 1st order RC filter like you are doing now. But separating the voltage sense from the ground plane allows you to measure the true voltage at the point where you are measuring it without worrying about how the current is affecting the reading. Like I said, this may be overboard for a dyno, and if you are just breadboarding this it would be difficult to achieve anyway. Speaking of, do you plan on building your own pcb and break out the mcu from the dev board at some point? If so, that is a consideration for the mcu choice.
I was hoping to avoid making my own board. I bought some protoboards that plug right into the top of the Minima which will provide enough space for me to put an opamp or two and some filtering. The current sensor boards are readily available on ebay or amazon so I don't plan to lay those out. There is also a user on here that laid out a board specifically for the MiniPro that I might be able to use if needed.

I did encounter a problem with the Minima being that the SimpleDyno software can't seem to connect to it over the serial connection. I haven't tried too many things yet but it isn't a good first problem. Unfortunately, the developer of SimpleDyno is no longer developing the software and I don't really want to go back to use Matlab/Octave to do the analysis. It is probably a fixable issue I just need to dig into it further.
kufman is offline  
Old 04-16-2024 | 08:21 AM
  #147  
trilerian's Avatar
Tech Elite
iTrader: (51)
 
Joined: Apr 2005
Posts: 2,393
From: Lexington KY
Default

Originally Posted by kufman
I was hoping to avoid making my own board. I bought some protoboards that plug right into the top of the Minima which will provide enough space for me to put an opamp or two and some filtering. The current sensor boards are readily available on ebay or amazon so I don't plan to lay those out. There is also a user on here that laid out a board specifically for the MiniPro that I might be able to use if needed.

I did encounter a problem with the Minima being that the SimpleDyno software can't seem to connect to it over the serial connection. I haven't tried too many things yet but it isn't a good first problem. Unfortunately, the developer of SimpleDyno is no longer developing the software and I don't really want to go back to use Matlab/Octave to do the analysis. It is probably a fixable issue I just need to dig into it further.
Did you use the first sketch you posted, the original from Simple Dyno? Can you get the info using a terminal emulator instead of Simple Dyno? With the IDE open and a USB connected can you see the info displayed with the Serial Monitor tool?
trilerian is offline  
Old 04-16-2024 | 08:32 AM
  #148  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by trilerian
Did you use the first sketch you posted, the original from Simple Dyno? Can you get the info using a terminal emulator instead of Simple Dyno? With the IDE open and a USB connected can you see the info displayed with the Serial Monitor tool?
Yes, I can watch the data flow just fine using serial monitor. The SimpleDyno software has always been a little weird with the serial port even on with the Nano. Usually have to hit connect twice on the Nano but it just will not connect with the Minima. I think the Minima does use a slightly different protocol than the Nano but I don't know enough about the nitty gritty of USB to know what the difference is.
kufman is offline  
Old 04-20-2024 | 06:53 AM
  #149  
GerryH's Avatar
Tech Fanatic
iTrader: (29)
 
Joined: Nov 2009
Posts: 978
Default

Is the delay() after the serial.flush() needed to keep the SimpleDyno side from buffer overflow? You're sending 89 characters per sample @ 20 samples/sec = 1780 characters/sec , theoretical speed at 115200baud = 14,440 char/sec Just realized that's how you're setting the samples/sec. PDR's method is better and non-blocking.

If you're doing 4 interrupts per revolution, at say 12000 rpm, that's 800 interrupts per second. The delay(20) stops interrupt service routines, so your timing subroutine is getting blocked.

Also it's somewhat inefficient to build a string to send to serial. Just serial.print() each line followed by a serial.println()
kufman likes this.

Last edited by GerryH; 04-20-2024 at 07:09 AM.
GerryH is offline  
Old 04-20-2024 | 05:10 PM
  #150  
kufman's Avatar
Tech Elite
iTrader: (7)
 
Joined: Feb 2004
Posts: 3,787
From: Elburn, IL
Default

Originally Posted by GerryH
Is the delay() after the serial.flush() needed to keep the SimpleDyno side from buffer overflow? You're sending 89 characters per sample @ 20 samples/sec = 1780 characters/sec , theoretical speed at 115200baud = 14,440 char/sec Just realized that's how you're setting the samples/sec. PDR's method is better and non-blocking.

If you're doing 4 interrupts per revolution, at say 12000 rpm, that's 800 interrupts per second. The delay(20) stops interrupt service routines, so your timing subroutine is getting blocked.

Also it's somewhat inefficient to build a string to send to serial. Just serial.print() each line followed by a serial.println()
Ya, I knew the stock code probably wasn't great but it was provided with the Simple Dyno software. I have written others for use with my Octave script. I tried PDR's code and it works well. I also tried to move to the Arduino minima for better performance but the simple Dyno software is having troubles connecting. I also did a dump to an array test and it works very well with the Minima. Worked so well that you can see the asymmetry in my 3d printed disk.
kufman is offline  


Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service -

Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.