The Homebuilt Dynamometer (Dyno)Thread!!!
#136
Tech Master
iTrader: (1)
Joined: Jun 2007
Posts: 1,627
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.
#137
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.
#138
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.
#140
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.
#141
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.
#142
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
#143
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.
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...
#144
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...
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 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.
#145
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.
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.
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.
#146
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.
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 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.
#147
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.
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.
#148
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.
#149
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()
Last edited by GerryH; 04-20-2024 at 07:09 AM.
#150
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()



16Likes