rev counter with DAC

I've managed to make a 20 segment LED bargraph and proved it works with an analog (rising voltage) input.

I have also proved a hall effect RPM cct and the related code to produce a RPM value.

When I use a PWM output and analog write the value out to the bar graph, I could RC filter the PWM but then I get 1/2 voltage rail readings and it is still flakey.

Would a DAC such as ;

work with this to provide a 0-5v voltage based on the RPM (frequency input)?

My RPM counter runs up to 10,000 so the 20 segment display scales for that. Would a DAC cope with the 0-10000.

Thanks

Hi,
What values are you using in the LP filter for the PWM?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

You may need to put a DC amplifier after the LP filter so as not to load it down, the gain of the amplifier will enable you to get 0 to 5Vdc range.

If you use a DAC, the fact that the RPM goes to 10,000 rpm is of no consequence as you have already scaled it for the LED ladder.

Thanks.. Tom... :slight_smile:

Tom

Thanks.

I'de rather not use the RC filter because it only gest me 1/2 the voltage rail to drive the bar graph so the question really is " is the DAC I hyperlinked to suitable"?

Will it give me the 0-5v I need to the bar graph?

Thanks

kev

kpg:
When I use a PWM output and analog write the value out to the bar graph, I could RC filter the PWM but then I get 1/2 voltage rail readings and it is still flakey.

Given that you seem to have both parts working separately that makes no sense without seeing your program and your schematic.

My guess is that there is something simple wrong with your program.

...R

Ok to be clearer...

The PWM output is fed via a 1k resistor than a .1 uf capacitor (to ground) to the input of 2 x LM2914 (bar graph drivers) to the 2 x 10 segment displays.

My issue is I probably haven't got the RC input values right because when I look with a simple voltmeter I can still see the voltage going up and down on the LM3914 inputs.

If I just put a varying voltage on the input of the LM3914's they display fine. So I just need a better RC choice or need to know if the DAC I referenced would solve the problem better.

The hall effect tacho circuit works and the code is

//use 5 v power rail for hall?????
// digital pin 2 is the hall pin
int hall_pin = 2;
// set number of hall trips for RPM reading (higher improves accuracy)
float hall_thresh = 10.0;
const int outPin1 = 7; //check is pwm output pin to drive lm3914

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the hall pin an input:
  pinMode(hall_pin, INPUT);
  pinMode (outPin1,OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // preallocate values for tach
  float hall_count = 1.0;
  float start = micros();
  bool on_state = false;
  // counting number of times the hall sensor is tripped
  // but without double counting during the same trip
  while(true){//keeps running while true but what makes it true?
    if (digitalRead(hall_pin)==0){//every time hall is switched to 0 run if
      if (on_state==false){//already set to false so make true
        on_state = true;
        hall_count+=1.0;//count = (hall_count + 1.0) + new value of hall_count
      }
    } else{
      on_state = false;
    }

   // Serial.println (on_state);
    
    if (hall_count>=hall_thresh){
      break;
    }
  }
  //Serial.print(on_state);
  // print information about Time and RPM
  float end_time = micros();
  float time_passed = ((end_time - start)/1000000.0); //micros now - start micros/1second
  Serial.print("Time Passed: ");// in seconds
  Serial.print(time_passed);
  Serial.println("s");
  float rpm_val = (hall_count/time_passed)*60.0;
  Serial.print(rpm_val);
  Serial.println(" RPM");
  delay(1);        // delay in between reads for stability
  analogWrite (outPin1, rpm_val);//send pwm voltage to lm3914
}

Any feedback on the RC circuit values or the DAC chip please?

Appreciate the help guys... :slight_smile:

kpg:
I've managed to make a 20 segment LED bargraph and proved it works with an analog (rising voltage) input.

Is that done using an Arduino?

Post a link to the datasheet for the bargraph device.

...R

Yes it is on an Arduino mega.

Link to bar graph driver chip is;

This bit all works perfectly as does the generation of an RPM value.

Its just converting the PWN to an analog voltage (0-5v) that I am missing. My current RC network obviously isn't good enough and maybe the DAC I referenced is better?

Thanks

Instead of adding more hardware, could always just drive the bar graphs directly off the mega, skip the whole PWM to analog parts..

kpg:
Yes it is on an Arduino mega.

Please post the program.

...R

Robin

Code attached. I posted the same earlier.

I don't want to use lots of hardware pins. I've got lots of other stuff going on and need them.

I just need to decide if a RC circuit is the way to go or should I buy a HC05 DAC.

//use 5 v power rail for hall?????
// digital pin 2 is the hall pin
int hall_pin = 2;
// set number of hall trips for RPM reading (higher improves accuracy)
float hall_thresh = 10.0;
const int outPin1 = 7; //check is pwm output pin to drive lm3914

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the hall pin an input:
  pinMode(hall_pin, INPUT);
  pinMode (outPin1,OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // preallocate values for tach
  float hall_count = 1.0;
  float start = micros();
  bool on_state = false;
  // counting number of times the hall sensor is tripped
  // but without double counting during the same trip
  while(true){//keeps running while true but what makes it true?
    if (digitalRead(hall_pin)==0){//every time hall is switched to 0 run if
      if (on_state==false){//already set to false so make true
        on_state = true;
        hall_count+=1.0;//count = (hall_count + 1.0) + new value of hall_count
      }
    } else{
      on_state = false;
    }

   // Serial.println (on_state);
    
    if (hall_count>=hall_thresh){
      break;
    }
  }
  //Serial.print(on_state);
  // print information about Time and RPM
  float end_time = micros();
  float time_passed = ((end_time - start)/1000000.0); //micros now - start micros/1second
  Serial.print("Time Passed: ");// in seconds
  Serial.print(time_passed);
  Serial.println("s");
  float rpm_val = (hall_count/time_passed)*60.0;
  Serial.print(rpm_val);
  Serial.println(" RPM");
  delay(1);        // delay in between reads for stability
  analogWrite (outPin1, rpm_val);//send pwm voltage to lm3914
}

The one thing I have just seen I haven't done is scale the rpm value output (rpm_val), at the moment it just reads the rpm number (3000 etc.) which is no good for a 0-5v analog input to the LM 3914.

So is that a straight divide i.e 10,000 (max RPM)/255/2.5 (if I use an RC filter that only give a max output of 2.5v)?

The one thing I have just seen I haven't done is scale the rpm value output (rpm_val), at the moment it just reads the rpm number (3000 etc.) which is no good for a 0-5v analog input to the LM 3914.

So is that a straight divide i.e 10,000 (max RPM)/255/2.5 (if I use an RC filter that only give a max output of 2.5v)?

No, you need to scale 0-10000 to 0-255 with

(rpm/10000) * 255

From the data sheet

(2) Pin 5 input current must be limited to ±3mA. T

With your 1K in the RC filter you have 5ma, so I would increase the resistor value.

use an RC filter that only give a max output of 2.5v

Something is wrong here. How are you measuring the output?

The PWM output goes through the RC filter into the LM3914. The RC seems to drop the 5v PWM signal to 2.5v approx.

I changed the 1k to a 2k and current seems better, Thanks.

It actually all works now after a fashion but my question is still "should I use a DAC instead of the RC circuit"? My LM3914 cct looks for 5v to light all 20 LED's (which I would rescale but would loose resolution), and I am assuming the DAC would be better?

The RC seems to drop the 5v PWM signal to 2.5v approx.

This is wrong, and if you don't have the hardware skills required to figure this out, then the DAC is a foolproof solution.

If your Arduino output to the RC filter is digitalWrite(outPin1, HIGH) or analogWrite(outPin1, 255) what do you see at the LM3914 input?

kpg:
(which I would rescale but would loose resolution)

Actually, no you,won’t.

Your resolution can only be 20 steps no matter what voltage range you dealing with. (Actually you can have a lot of fun with bargraphs to display wider readings such as start flashing digits to show increments past full.)

It doesn’t matter if 9,000 rpm gets turned in 1v, 5v, or 1000v as long as your proportional to the output for say 8,500 and 9,500.

with analog.write at 255 I see 4.45v at the input of the RC and very near the same at the output so it isn't dropping much.

So looks good. Will get a scope tomorrow and probe it.

Thanks again

kpg:
Code attached. I posted the same earlier.

There was not much point duplicating an earlier Post.

That program is for the RPM stuff. I would like to see the program that works with the bargraph.

...R

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Guys

There is no code for the bar graph driver. I just feed it the PWM value (rpm_val) through the RC filter as an input voltage.

I will post the circuit later but its basically the cascaded 20 segment (2 displays) one in several on-line projects.

Thanks again for the feedback