0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« on: January 15, 2009, 09:28:30 pm » |
My project is a shield for the Arduino. It is designed to monitor engine knock voltage from peizo sensor w/ conditioning circuit, determine RPM via a frequency to voltage convertor, determine when knock is present by verification against RPM, datalog on serial, and display on a LCD. I am currently considering a s/w problem because I wrote the code.  I think I did a pretty good job on my code, it's structure, and comment it, but there must be a problem with it somewhere. Any help is greatly appreciated! Edit: The voltages do not even remotely reflect the actual voltage as measured by a meter. Here is the code: http://www.squirrelpf.com/knockboard/code.txtThanks, Frank
|
|
|
|
« Last Edit: January 16, 2009, 07:05:31 am by fkatzenb »
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15314
Measurement changes behavior
|
 |
« Reply #1 on: January 15, 2009, 11:04:45 pm » |
Well you might start by telling us what works and what doesn't work ;D
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« Reply #2 on: January 16, 2009, 07:05:54 am » |
Wow... nicely done Frank. LOL. Fixed description.
|
|
|
|
« Last Edit: January 16, 2009, 01:35:46 pm by fkatzenb »
|
Logged
|
|
|
|
|
Bristol, UK
Offline
Edison Member
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
|
 |
« Reply #3 on: January 16, 2009, 12:16:43 pm » |
So, what was the problem? How did you fix it? It's useful to know, because others will search these forum postings for help when they have the same kind of trouble.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« Reply #4 on: January 16, 2009, 01:35:04 pm » |
The problem isn't fixed. i just fixed my post which didn't describe what was wrong.
|
|
|
|
|
Logged
|
|
|
|
|
Connecticut, US
Offline
Edison Member
Karma: 1
Posts: 1036
Whatduino
|
 |
« Reply #5 on: January 16, 2009, 03:52:23 pm » |
Hm. It "does not remotely reflect the voltages" the way you expect. How about telling us more? What's producing the voltage? What range of voltages do you read with a meter? Where are you sending that signal? How are you reading that signal? What range of readings do you get? Is the reading high when the meter shows a high voltage? Is the reading low when the meter shows a low voltage? Are the readings noisy? random? clipped? inverted? not the same number you see on the meter? ... How to ask questions the smart way.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« Reply #6 on: January 16, 2009, 03:58:39 pm » |
Well I figured people would give it a try. Put to run it down, 5 volts would appear around 1 volt and it tens to fluctuates a bit. If I change it to 4 volts, it would still be just a bit less then 1 volt.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« Reply #7 on: January 19, 2009, 01:54:41 pm » |
Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 55
Arduino rocks
|
 |
« Reply #8 on: January 19, 2009, 07:03:25 pm » |
I suspect you have a issue of mixing byte with floating point.
byte knock_volt; // this is the raw knock voltage at any instance in time
0-255 is all that knock_volt will ever contain. It will rollover to 0 when it reaches 256.
knock_volt = analogRead(knockPin); // grab the sensor data for the knock sensor knock_volt = map(knock_volt, 0, 1023, 0, 255); // remap the 10-bit input to 8-bit
Okay, you even map the 10 bits down to 8. May be better to keep the 10 bits and use INT as you lose precision.
Serial.print(knock_volt, DEC); Serial.print("\t");
That should show a value between 0-255?
printDouble(knock_volt * 0.019531, 3); // Knock Volts
- knock_volt is not a double - knock_volt * 0.019531 ?
255 the maximum knock_volt can be * 0.019531 is never going to be more than 4.
I suggest you do the scaling completely with integer (x10 or x100), then insert the decimal for printing.
For example... knock_bits 0-1023 or 0-5V
knock_bits = 511 or 2.5V or 204.4 bits per volt. since we want two decimal place precision voltsPerBit = 2044
long volts (because int will overflow)
volts = (knock_bits * 1000) / 2044
volts now contains the actual volts * 100 Very fast, no floating point. It's just a matter of formatting the output.
Avoid using floating point. When reading only 1024 bits, the precision is ony 1 bit or 1/1000 easy to handle without floating point.
Hope that helps.
|
|
|
|
« Last Edit: January 19, 2009, 07:03:41 pm by matthewsg »
|
Logged
|
|
|
|
|
Connecticut, US
Offline
Edison Member
Karma: 1
Posts: 1036
Whatduino
|
 |
« Reply #9 on: January 19, 2009, 08:09:47 pm » |
As George says, you're losing data in knock_volt. byte knock_volt; knock_volt = analogRead(knockPin); knock_volt = map(knock_volt, 0, 1023, 0, 255); After this, the highest value you could have in knock_volt is 63. What's worse, the value 63 will appear when the voltage is at 1/4, 1/2, 3/4 and full levels.
|
|
|
|
« Last Edit: January 19, 2009, 08:11:03 pm by halley »
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 60
Arduino rocks
|
 |
« Reply #10 on: January 19, 2009, 08:18:32 pm » |
Thanks folks! That took care of it! Lesson learned!
|
|
|
|
|
Logged
|
|
|
|
|
|