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.
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"?
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.
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
}
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?
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?
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.