PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post Reply
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

Hello everyone.
does anyone know thoroughly exactly how to set up a PWM OUT so as to get a reasonable signal for a car tachometer? For example, I need to receive two pulses in one physical revolution (as it was with the native internal combustion engine).
evil neodymium :twisted:
Zieg
Posts: 140
Joined: Mon Apr 25, 2022 3:31 am
Has thanked: 58 times
Been thanked: 52 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Zieg »

If you're taking about doing this from the Openinverter board, I don't believe that's possible. It's not PWM anymore, it's a frequency output tht you need

I'm in the same boat, I've searched the forum and so far the best option seems to be to use a Teensy or similar microcontroller with the appropriate hardware to talk to the inverter over CANbus, and then output a Tone() with the frequency scaled appropriately.

Do note there is a certain minimim frequency that can be output due to limitations in the hardware. For the specific board I was looking at, I believe it was ~20 Hz.
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by johu »

There is a frequency mode from 1 Hz to 500 Hz, resolution isn't great though. E.g. there is just one step from 250 to 500 Hz
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by arber333 »

Romale wrote: Sat Apr 08, 2023 4:33 pm Hello everyone.
does anyone know thoroughly exactly how to set up a PWM OUT so as to get a reasonable signal for a car tachometer? For example, I need to receive two pulses in one physical revolution (as it was with the native internal combustion engine).
Depends on what do you want the signal to do additionaly than show RPM... maybe also show speed?

I used a magnet (or two) on the driveshaft to input the speed and RPM since i am not using transmission
https://leafdriveblog.wordpress.com/202 ... l-trouble/

And i assembled Nano circuit to interpret the signal as 60 slots - 2 slots lengthened as per the original engine RPM sensing ring
https://leafdriveblog.wordpress.com/202 ... r-working/

Some of the forum members helped with code...
viewtopic.php?f=9&t=52
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

arber333 wrote: Sat Apr 08, 2023 7:41 pm Depends on what do you want the signal to do additionaly than show RPM... maybe also show speed?

I used a magnet (or two) on the driveshaft to input the speed and RPM since i am not using transmission
https://leafdriveblog.wordpress.com/202 ... l-trouble/

And i assembled Nano circuit to interpret the signal as 60 slots - 2 slots lengthened as per the original engine RPM sensing ring
https://leafdriveblog.wordpress.com/202 ... r-working/

Some of the forum members helped with code...
viewtopic.php?f=9&t=52

It's all very cumbersome and complicated. In this case, it is really easier to put two magnets on the motor shaft and a simple ss411a hall sensor for example. I only need one thing from the PWM OUT, - pulses for the tachometer. I really hoped that OI is able to give these impulses, because he knows quite accurately how many rpms at any given time.
evil neodymium :twisted:
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

johu wrote: Sat Apr 08, 2023 6:32 pm There is a frequency mode from 1 Hz to 500 Hz, resolution isn't great though. E.g. there is just one step from 250 to 500 Hz
Can I have a few more details about this situation? This may be suitable for an ordinary car tachometer in a native dashboard or purchased separately for example with Aliexpress? what values should I try to register in the output settings fields from the OI board ? We need a simple pulse, we don't need complex CAN data. I would like the simplest ancient tachometers to work
evil neodymium :twisted:
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

Ill. if it is not possible to get an out from the PWM, in general, do not invent anything and do not glue magnets. you can simply open the cover of the Nissan leaf motor and paste one ss411a hall between the grooves of the motor hide. this will give a very high-quality 4 pulses per revolution.
evil neodymium :twisted:
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by arber333 »

Romale wrote: Sat Apr 08, 2023 8:11 pm Ill. if it is not possible to get an out from the PWM, in general, do not invent anything and do not glue magnets. you can simply open the cover of the Nissan leaf motor and paste one ss411a hall between the grooves of the motor hide. this will give a very high-quality 4 pulses per revolution.
Why not just make a CAN micro controller which will listen to openinverter CAN report and drive your RPM indicator and other stuff?
See here for OI report https://openinverter.org/wiki/CAN_communication
ESP32 is a good choice as you could also use its wifi module.
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

arber333 wrote: Sun Apr 09, 2023 7:38 am Why not just make a CAN micro controller which will listen to openinverter CAN report and drive your RPM indicator and other stuff?
See here for OI report https://openinverter.org/wiki/CAN_communication
ESP32 is a good choice as you could also use its wifi module.

I 'm ashamed to admit , but I don 't understand CAN at all . for me, any programming is a very dark forest. With great difficulty I defeated the firmware of the board and the WIFI module with ready - made kits )
evil neodymium :twisted:
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by arber333 »

Romale wrote: Sun Apr 09, 2023 8:58 am I 'm ashamed to admit , but I don 't understand CAN at all . for me, any programming is a very dark forest. With great difficulty I defeated the firmware of the board and the WIFI module with ready - made kits )
Dont be, I myself am a mechanical engineer with a healthy dose of fear towards microcontrolers :). I now know how to lay some conditionals... though I am still trying to wrap my head around state machine code...

If you want i could send you one of my Nano shields so you can experiment and learn.
Idea is to get some sort of signal and translate it to RPM. If OI would send PWM with variable frequency you can use that signal to convert it to your engine flywheel signal.

Hm... on the other hand i think i can put together a CAN thing and you can get CAN data with much greater resolution. Not limited to RPM but also speedo, temperature, DC voltage and approximate DC current too. Maybe would be worth it to have? What do you use for voltage/current info?
yaroslav
Posts: 176
Joined: Tue Aug 13, 2019 4:32 pm
Location: Russia, Stavropol
Has thanked: 14 times
Been thanked: 5 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by yaroslav »

hi. I also ran into such a problem on my Audi a4, I put together a device that listens to can and translates into a meander with a frequency that varies depending on the RPM
yaroslav
Posts: 176
Joined: Tue Aug 13, 2019 4:32 pm
Location: Russia, Stavropol
Has thanked: 14 times
Been thanked: 5 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by yaroslav »

I made the first device on arduino, I can put all the material on it here, the minus is that it does not always read can, I am currently developing the second device on stm32
yaroslav
Posts: 176
Joined: Tue Aug 13, 2019 4:32 pm
Location: Russia, Stavropol
Has thanked: 14 times
Been thanked: 5 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by yaroslav »

Here is the code for arduino
Attachments
freq.ino
(1.9 KiB) Downloaded 64 times
yaroslav
Posts: 176
Joined: Tue Aug 13, 2019 4:32 pm
Location: Russia, Stavropol
Has thanked: 14 times
Been thanked: 5 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by yaroslav »

you will also need the mc2515 modules

https://aliexpress.ru/item/32817132818. ... 85d1blr7QV

and arduino nano
yaroslav
Posts: 176
Joined: Tue Aug 13, 2019 4:32 pm
Location: Russia, Stavropol
Has thanked: 14 times
Been thanked: 5 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by yaroslav »

and here is the second device on stm32, I almost wrote the program code, it remains to debug a little, the problem is that the tachometer sometimes jumps, I'll deal with it later
Attachments
can_stm32.jpg
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

arber333 wrote: Sun Apr 09, 2023 11:58 am
Hm... on the other hand i think i can put together a CAN thing and you can get CAN data with much greater resolution. Not limited to RPM but also speedo, temperature, DC voltage and approximate DC current too. Maybe would be worth it to have? What do you use for voltage/current info?

I used a cheap version of a wattmeter with a current ring. it monitors the battery voltage, battery current and temperature by one external sensor (I attached it to the inverter).

Yes, it would be ideal to receive all the signals on the can bus for a beautiful dashboard with a speedometer, tachometer, power and forecast of the remaining kilometers, depending on consumption, speed and remaining battery capacity.
Once I wanted to pay for such a development, but no one agreed to do it. If you create such a device compatible with the OI v3 board, so that it works on a simple screen, for example 12", it would be the limit of happiness)))
evil neodymium :twisted:
chentron
Posts: 103
Joined: Mon Feb 22, 2021 3:25 pm
Location: Spain
Has thanked: 42 times
Been thanked: 4 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by chentron »

Romale wrote: Sat Apr 08, 2023 8:11 pm Ill. if it is not possible to get an out from the PWM, in general, do not invent anything and do not glue magnets. you can simply open the cover of the Nissan leaf motor and paste one ss411a hall between the grooves of the motor hide. this will give a very high-quality 4 pulses per revolution.
In my EV conversion I expected to use pin18 of my O.I.v2 so that my tachometer would work but I was disappointed when reading this thread that this just not work. Believer in the KISS philosophy and without wanting to start learning how to program Arduino, I would like to know if someone has implemented a simple way to make the tachometer work, and the solution that Romale mentioned with ss411a comes to mind.
Zieg
Posts: 140
Joined: Mon Apr 25, 2022 3:31 am
Has thanked: 58 times
Been thanked: 52 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Zieg »

Yeah I'm also intrigued by that!
User avatar
rstevens81
Posts: 353
Joined: Sun Dec 22, 2019 10:36 am
Location: Bristol, UK
Has thanked: 23 times
Been thanked: 92 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by rstevens81 »

it needs to be done in software as the hardware timers do not work at low frequencies...the problem i found i hadwas it went in steps for the esp32 using hardware timers...(which used in the clip)... i will update with some arduino code for a nano shortly...

edit:
I believe this is code that can be adapted from a nano to generate a suitable tach signal:
https://github.com/chippernut/RPM-Signa ... erator.ino
(the esp32 does not have the tone command so it all gets more difficult)

I believe this will generate the signal if connected to an uln on the output and a resistor to create a +12v signal (reversed duty of course) ... or better yet a fan3112tmx (what i was using)
https://github.com/vdeschwb/esp32-signal-generator
to be of use for us you would need to unpick the code...i have been busy on the practical car stuff whilst it not been raining so haven't had a change to dig deeply.
pwm1.png
uln.png
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget 🤪
User avatar
rstevens81
Posts: 353
Joined: Sun Dec 22, 2019 10:36 am
Location: Bristol, UK
Has thanked: 23 times
Been thanked: 92 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by rstevens81 »

OK i'm an idiot!!! (Occam's razor)

The simplest way is the right way !!

This is basically a rehash of Blinkwithoutdelay (https://assiss.github.io/arduino-zhcn/c ... Delay.html)

as we a not dealing with super fast frequencies just using the raw rower of the esp32 is enough to create a smooth rpm sweep, my intentions is to create a function that deals with the timings on the second core ... but for now this is what works.

Also this works if you use a uln2003 and a resistor to +12v (pullup)


Code: Select all

const int ledPin =  26;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMicros = 0;        // will store last time LED was updated
long previousMillis = 0;        // will store last time LED was 

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000000;           // interval at which to blink (milliseconds)
long update_interval = 50;           // interval at which toupdate/print
float myrpm =500;
int dirn =1;

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
  Serial.begin(115200);
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMicros = micros();
  
  if(currentMicros - previousMicros > interval) {
    // save the last time you blinked the LED
    previousMicros = currentMicros;  

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > update_interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;  
    
    interval =  15000000/myrpm;  // RPM to Time
    Serial.print (myrpm);
    Serial.print ("/min ");
    Serial.print (interval);
    Serial.println (" microseconds");
    if (dirn==1) { myrpm=myrpm+100;}
    if (dirn==0) { myrpm=myrpm-100;}    
    if (myrpm >7500) {dirn=0;}
    if (myrpm <500) {dirn=1;}
  }

}
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget 🤪
User avatar
Romale
Posts: 451
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 214 times
Been thanked: 49 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by Romale »

rstevens81 wrote: Wed Oct 11, 2023 8:08 pm OK i'm an idiot!!! (Occam's razor)

The simplest way is the right way !!

This is basically a rehash of Blinkwithoutdelay (https://assiss.github.io/arduino-zhcn/c ... Delay.html)

as we a not dealing with super fast frequencies just using the raw rower of the esp32 is enough to create a smooth rpm sweep, my intentions is to create a function that deals with the timings on the second core ... but for now this is what works.

Also this works if you use a uln2003 and a resistor to +12v (pullup)


Code: Select all

const int ledPin =  26;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMicros = 0;        // will store last time LED was updated
long previousMillis = 0;        // will store last time LED was 

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000000;           // interval at which to blink (milliseconds)
long update_interval = 50;           // interval at which toupdate/print
float myrpm =500;
int dirn =1;

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
  Serial.begin(115200);
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMicros = micros();
  
  if(currentMicros - previousMicros > interval) {
    // save the last time you blinked the LED
    previousMicros = currentMicros;  

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > update_interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;  
    
    interval =  15000000/myrpm;  // RPM to Time
    Serial.print (myrpm);
    Serial.print ("/min ");
    Serial.print (interval);
    Serial.println (" microseconds");
    if (dirn==1) { myrpm=myrpm+100;}
    if (dirn==0) { myrpm=myrpm-100;}    
    if (myrpm >7500) {dirn=0;}
    if (myrpm <500) {dirn=1;}
  }

}


It is very cool! just what you need. could you give more information for people far from programming? for example, a photo of the device, a connection diagram, etc. thank you!
evil neodymium :twisted:
User avatar
rstevens81
Posts: 353
Joined: Sun Dec 22, 2019 10:36 am
Location: Bristol, UK
Has thanked: 23 times
Been thanked: 92 times

Re: PWM OUT! the output for the tachometer, how to set it up correctly? Is it possible?

Post by rstevens81 »

I'm using my spaceballs board ..... https://oshwlab.com/EV-Team/spaceballs ...just because i have them to hand :) if your interested make sure you use the RevB as that's the most complete 4 layer board (the S3 version is WIP and based on using a XIAO ESP32S3 and is intended to be DIYable board with Through hole design). But there is no ne3ed for anything that elaborate as proto board with an aliexpress bits will work :)
revisions.png
If you need to generate a +12v signal then the arrangement below worked really well...
esp32_signal_pwm.png
if you omit the pull up resistor you can do negative switched pwm, which worked well to drive my fuel gauge :)
I like the ULN2003 as its cheap and comes in though hole for breadboarding or proto boarding :)
if you want switched or (Powerfull PWM e.g. small fan) +12v then your going to need to use something like FAN3122TMX this is a smd but damian uses it on his zombie.
For really easy PCB design i would recommend easyeda for beginners as its quite easy to pick up :) .. just make sure you check for DRC errors before manufacture :)
DRC.png
DRC.png (10.34 KiB) Viewed 6919 times
The actual coding is quite simple it loops round and we set an interval between the change of state from high to low once that time has been exceeded it switches.... the second timer is just used to increase and decrease that time to simulate increase and decrease in rpm.

Moving forward I Will be putting mycode in github (with much more explanation) which will take can messages from the car & BMS and convert them into signals (most of them PWM) once i have made some progress ill post in my build thread and post a link here :)
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget 🤪
Post Reply