Middrive Tachometer?

Joined
Feb 6, 2019
Messages
333
Hey, I'm building my first e bike. It's a middrive and I thought it would be kind of cool if I could add an analog tachometer like a car. I have two ideas for figuring out what rpm the motor is spinning at. The first being I guess a cadence sensor where the speed of the front crank is measured through magnets. The second idea I had was using something like this https://hobbyking.com/en_us/micropower-brushless-motor-rpm-sensor.html to measure the motor speed. In both situations I would wire it to an arduino which would control a stepper motor for the actual gauge and so on. Has anyone else tried anything like this? If so, how was it done? I'm guessing that working out a practical way to measure motor rpm is the harder part in this case.
 
Im getting into this. You could use many different approaches. what waveform does the rpm sensor make? I would think a car dash tach signal would be easier to replicate if you want an analog gauge. You could get rid of the Ardriuno. There are also optical pickups, or even an audiotach app on your cell phone running in real time. Thata quick and easy way. Regardless, following.
 
Assuming you want a digital count of the RPM, then if the motor has hall sensors, you simply connect to one of those, count the pulses from it, and divide by the number of pole pairs the motor has (number of magnets divided by two).

That's what the Cycle Analyst does to measure speed, if not using an external wheel sensor.


Driving an analog tach, I guess it depends on how the tach is made. If the gauge you use is simply a voltmeter, then you don't even need to "count" the pulses or anything. You can just use an op-amp integrator circuit, setup such that it's max output voltage drives the gauge to full range, and its' min output lets it fall to zero. Then use something (555 in oneshot mode, etc) that takes the pulses from the hall sensor on the motor and creates a "PWM" from them to cause the integrator to rise in voltage the faster the pulses come, to drive the tach gauge higher and higher.

You can get a lot more complicated than that, but you don't have to.
 
DogDipstick said:
Im getting into this. You could use many different approaches. what waveform does the rpm sensor make? I would think a car dash tach signal would be easier to replicate if you want an analog gauge. You could get rid of the Ardriuno. There are also optical pickups, or even an audiotach app on your cell phone running in real time. Thata quick and easy way. Regardless, following.

There isn't much information about it on the site, but I found the owner's manual for it: https://cdn-global-hk.hobbyking.com/media/file/104903002X569681X7.pdf I'm not too sure how it works but it seems like it measures the pulses that the controller sends to the motor. An app on your phone would be easier but I would just prefer if everything was integrated into the bike. I actually thought of using a car tachometer but where would I wire it up to? I know for most of them you would normally wire them to the spark plug but where would you do that for a brushless dc motor?
 
amberwolf said:
Assuming you want a digital count of the RPM, then if the motor has hall sensors, you simply connect to one of those, count the pulses from it, and divide by the number of pole pairs the motor has (number of magnets divided by two).

That's what the Cycle Analyst does to measure speed, if not using an external wheel sensor.


Driving an analog tach, I guess it depends on how the tach is made. If the gauge you use is simply a voltmeter, then you don't even need to "count" the pulses or anything. You can just use an op-amp integrator circuit, setup such that it's max output voltage drives the gauge to full range, and its' min output lets it fall to zero. Then use something (555 in oneshot mode, etc) that takes the pulses from the hall sensor on the motor and creates a "PWM" from them to cause the integrator to rise in voltage the faster the pulses come, to drive the tach gauge higher and higher.

You can get a lot more complicated than that, but you don't have to.

I believe the sensor does the first thing you said, and that's interesting actually I haven't heard of using a voltmeter for measuring rpms. I suppose that could work though? I was actually planning on building the gauge from scratch and programming a stepper motor to move the needle to the corresponding position on the gauge, and doing the first thing you said.
 
If you tap into a hall sensor signal wire from the motor, it will send pulses as the motor spins. It will be 50% duty cycle and the number of pulses per revolution will be equal to the number of magnet pairs on the rotor.

An Arduino could count the pulses directly and drive the stepper.
 
fechter said:
If you tap into a hall sensor signal wire from the motor, it will send pulses as the motor spins. It will be 50% duty cycle and the number of pulses per revolution will be equal to the number of magnet pairs on the rotor.

An Arduino could count the pulses directly and drive the stepper.

Thanks for the response, what would I use to connect the hall sensor signal wire to the Arduino, and where would I connect it on there? Sorry if that's a stupid question, I'm completely new at this stuff.
 
It's just a digital signal, normally 0-5v, so it goes to any 5v-capable digital input of whatever MCU you use. However, if it is a 3v MCU it migth need translation logic or a voltage divider, etc., depends on how that MCU / board works.

Personally I'd go with the relatively simple analog circuit, but if you already know how to program arduino/etc (or wanted to learn for future projects anyway), the MCU based one could be experimented with or modified easily enough.
 
amberwolf said:
It's just a digital signal, normally 0-5v, so it goes to any 5v-capable digital input of whatever MCU you use. However, if it is a 3v MCU it migth need translation logic or a voltage divider, etc., depends on how that MCU / board works.

Personally I'd go with the relatively simple analog circuit, but if you already know how to program arduino/etc (or wanted to learn for future projects anyway), the MCU based one could be experimented with or modified easily enough.

I guess that makes it simpler than I thought then. Yeah, I do want to learn how to program an arduino so I'll most likely go that route just to get the experience of it.
 
It's been a while but I finally got back to working on this I guess. So I think I'm just going to get my arduino to count the pulses from a hall sensor wire and then do the appropriate calculations to give me the rpm. I was looking at the wiring diagram for the motor controller and there are three hall sensor wires: https://electricbike.com/forum/filedata/fetch?id=57909&d=1520442585 Does it matter which wire I connect to? Or is there like a specific one I need to tap into? Also what would these "pulses" look like? Would they be sudden drops and increases of voltage?
 
Doesn't matter which one of the signals you use. Each one is just slightly different timing/position from the others. Since you're just counting them, that's not relevant.

Pulses are by definition (well, mostly) increases and decreases in voltage (or current, or both). But there are a lot of different kinds, and very little in the "digital" world actually comes as pure on/off signals. There's always noise, and it can be enough to swamp your counter with zillions of false pulses, if it's bad enough.

Also keep in mind it isn't the controller you're monitoring. It's the motor. The controller is just providing the power and pullup resistors.

But given the questions...you might want to go thru the tutorials over on AllAboutCircuits for the various kinds of electronics, because you're probably going to have to at least build an interface circuit to the arduino. At the least, the digital electronics sections, if you already know about analog (resistor, capacitor, etc) stuff. You may not have to read everything, but whatever you can, will teach you stuff you might need to know. :)
 
amberwolf said:
Doesn't matter which one of the signals you use. Each one is just slightly different timing/position from the others. Since you're just counting them, that's not relevant.

Pulses are by definition (well, mostly) increases and decreases in voltage (or current, or both). But there are a lot of different kinds, and very little in the "digital" world actually comes as pure on/off signals. There's always noise, and it can be enough to swamp your counter with zillions of false pulses, if it's bad enough.

Also keep in mind it isn't the controller you're monitoring. It's the motor. The controller is just providing the power and pullup resistors.

But given the questions...you might want to go thru the tutorials over on AllAboutCircuits for the various kinds of electronics, because you're probably going to have to at least build an interface circuit to the arduino. At the least, the digital electronics sections, if you already know about analog (resistor, capacitor, etc) stuff. You may not have to read everything, but whatever you can, will teach you stuff you might need to know. :)

Yikes honestly the false pulses part scares me. Is it even practical to count these pulses with an arduino then? I agree, I do need to learn more about all this stuff, I'll check out that page. I mean idk would it just be easier for me to measure my rpm through the front crankset with a reed switch? (thats what I'm doing for my speedometer and it seems to work)
 
It doesn't necessarily take much to damp out "false pulses", and it can even be done in software as long as they're not of too high a voltage/etc that the MCU input can't handle it.

(it's not likely, but it *is* possible--I had a controller blow up from an induced signal into a sense and power line on a thermal sensor--it actually damaged the 5v power supply itself, along with various things attached to it. It was not a short to any power or motor phase, just voltage spikes induced from the motors into the trike frame itself, which acts as a giant antenna, and which *was* shorted (probably) to the 5v or thermal sensor line (I forget which).)

But knowing why they happen and what you can do about it will help you make the best stuff you can that won't fail from wierd stuff that happens. :)

(if the thermal sensor had been designed to be read from sensor to *ground* instead of sensor to 5v, it is highly unlikely that the same conditions would have caused any fault other than potentially incorrect thermal readings. The next revision of the controller is probably going to be made that way for that reason.)




The reed switch can generate false pulses just as well, from vibration, etc. The spedometer electronics on a bike computer, cycle analyst, controller, etc., also have filtering (electronic or software or both) to eliminate those spurious signals and count only the ones that would actually be made by the wheel turning.

In electronics, there's a number of hardware ways to do it, from simple and mostly reliable, to complex and "completely" reliable ;) . There's also software ways to do it, like only counting pulses that stay "on" for so many clock cycles, and *also* stay *off* for so many clock cycles. Anything else is "obviously" ;) not a real pulse, because your wheel could never spin fast enough to trigger shorter pulses than that. Reading a motor's RPM is a little less easy, because it's usually much faster than a wheel RPM, so you have more chances for spurious signals to make it thru your simple filter. So a slightly more complex filter might be necessary (might not). Sometimes a combination of hardware and software filtering works better.


Ssometimes you get *no* spurious signals from a system, and you don't need any of that claptrap. :) You have to build it and find out...but if you do get problems, there's always things you can do about them...if you understand why they are happening and what kinds of things might keep them from doing so.
 
amberwolf said:
It doesn't necessarily take much to damp out "false pulses", and it can even be done in software as long as they're not of too high a voltage/etc that the MCU input can't handle it.

(it's not likely, but it *is* possible--I had a controller blow up from an induced signal into a sense and power line on a thermal sensor--it actually damaged the 5v power supply itself, along with various things attached to it. It was not a short to any power or motor phase, just voltage spikes induced from the motors into the trike frame itself, which acts as a giant antenna, and which *was* shorted (probably) to the 5v or thermal sensor line (I forget which).)

But knowing why they happen and what you can do about it will help you make the best stuff you can that won't fail from wierd stuff that happens. :)

(if the thermal sensor had been designed to be read from sensor to *ground* instead of sensor to 5v, it is highly unlikely that the same conditions would have caused any fault other than potentially incorrect thermal readings. The next revision of the controller is probably going to be made that way for that reason.)




The reed switch can generate false pulses just as well, from vibration, etc. The spedometer electronics on a bike computer, cycle analyst, controller, etc., also have filtering (electronic or software or both) to eliminate those spurious signals and count only the ones that would actually be made by the wheel turning.

In electronics, there's a number of hardware ways to do it, from simple and mostly reliable, to complex and "completely" reliable ;) . There's also software ways to do it, like only counting pulses that stay "on" for so many clock cycles, and *also* stay *off* for so many clock cycles. Anything else is "obviously" ;) not a real pulse, because your wheel could never spin fast enough to trigger shorter pulses than that. Reading a motor's RPM is a little less easy, because it's usually much faster than a wheel RPM, so you have more chances for spurious signals to make it thru your simple filter. So a slightly more complex filter might be necessary (might not). Sometimes a combination of hardware and software filtering works better.


Ssometimes you get *no* spurious signals from a system, and you don't need any of that claptrap. :) You have to build it and find out...but if you do get problems, there's always things you can do about them...if you understand why they are happening and what kinds of things might keep them from doing so.

Ah okay, thanks for the help! I'll try it anyways and see how well it works. :D
 
There are lots of devices that get speed from the halls signals, like the CA, for example. I don't think you will have problems.

A simple low pass filter to take out the PWM frequency should be all you need, if that.
 
fechter said:
There are lots of devices that get speed from the halls signals, like the CA, for example. I don't think you will have problems.

A simple low pass filter to take out the PWM frequency should be all you need, if that.

Would the programming be complicated or hard to get rid of the false positives though? I'm starting to realize the drawbacks of using a reed switch for my speedometer, it isn't very accurate and gets false positives all the time, is it anything like that? I'm thinking maybe I should just read the rpm through the cranks with an IR sensor or something.
 
If you search the Arduino site for "switch debouncer" you can probably find some code for that. Reed switches can bounce, but not hall sensors.
 
fechter said:
If you search the Arduino site for "switch debouncer" you can probably find some code for that. Reed switches can bounce, but not hall sensors.

Ah thanks, got it working right today. :) So hall sensors aren't as much of a pain to read off of then?
 
Why would you want this?
*To keep the motor in its optimal range I'd assume. Might as well go a step further, and insert some temperature probes and maybe even a little stethoscope to see how the gears are doing. A cool idea!
 
speedyebikenoob said:
fechter said:
If you search the Arduino site for "switch debouncer" you can probably find some code for that. Reed switches can bounce, but not hall sensors.

Ah thanks, got it working right today. :) So hall sensors aren't as much of a pain to read off of then?

No, they shouldn't be other than I'm not sure what the trigger threshold is for the Arduino digital input. A "low" on a hall sensor might be around 0.7v, so if the trigger threshold is close to that, you could run into problems. A simple resistor voltage divider or diode could be used to lower the low signal level to make sure it's in the right range.
 
markz said:
Why would you want this?
*To keep the motor in its optimal range I'd assume. Might as well go a step further, and insert some temperature probes and maybe even a little stethoscope to see how the gears are doing. A cool idea!

There is really no purpose lol. Just like you don't really need a tach on a car either, you can just tell by the pitch if you drive the car enough what speed you need to shift at and at what rpm its most efficient. But you can't say it's not going to look cool though, not many e bikes have an analog tach :D
 
fechter said:
speedyebikenoob said:
fechter said:
If you search the Arduino site for "switch debouncer" you can probably find some code for that. Reed switches can bounce, but not hall sensors.

Ah thanks, got it working right today. :) So hall sensors aren't as much of a pain to read off of then?

No, they shouldn't be other than I'm not sure what the trigger threshold is for the Arduino digital input. A "low" on a hall sensor might be around 0.7v, so if the trigger threshold is close to that, you could run into problems. A simple resistor voltage divider or diode could be used to lower the low signal level to make sure it's in the right range.

Great! Thanks so much
 
Back
Top