PDA

View Full Version : Can you teach a PIC to learn?



lew247
- 20th December 2009, 16:27
I'm thinking about starting a project that would basically mean the PIC having to learn.

Ill explain in the simplest analagies I can think of.

Picture a fuel guage, it works by having a variable resistor at the end, the resistance changes by going higher or lower resistance as the fuel goes higher or lower in the tank.

What I need to do is light 3 led's one for 3/4 full, one for half full and one for 1/4 full.


The problem I have is on each car the resistance for those measurments are totally different, and in some cases reversed.

My solution would be have the pic read the resistance attached to a pin or air of pins? say for instance I pour 1/4 of the liquid in the tank, then press a button, the pic would measure that resistance and store it in eeprom position 3, half full measure again and store in eeprom location 4, 3/4 full and store the resistance in location 5, and full store the resistance in location 6.
Theoretically if I can do this then when the "fuel" lever drops, I should be able to get it to compare the resistance on the pin and when it reaches the stored limits in any of the eeprom positions, It would activate one or more of the led's depending on the level.

Sorry if I'm not explaingin it very well I'm still very new at this pic lark and not certian of the terminology and in a lot of cases I'l learning as I'm going.

In this case I have no idea what I'd need or how to go about it, but if it is possible some ideas would be very welcome as would some sample code for those ideas, once I get the idea of what I'm actually meant to be doing I should be able to work it all out and hopefully complete it.

Its not a commercial project or school project, it's just an idea I have that could be used on several other ideas in the back of my head.

Any suggestions and or help very welcome.

Acetronics2
- 20th December 2009, 16:47
Hi, lew

There are nots lots of solutions ...

just put 0, X, Y, Z , Full gallons in your tank ( corresponding to your Leds ) and valid Each PIC measurement with a stupid pushbutton ...

"Analog" display ( liters ) will need some more maths to find the best fit curve ...

two constants ... the non linear response AND the "12v" supply voltage influence ...

one more thing to know ... some gages output Voltage like a pot , some are variable resistors and you must create a current generator.

That's all ...

Alain

Charles Linquis
- 20th December 2009, 20:59
You can solve the variable 12V problem by generating Vref from a voltage divider off the 12V. If you do it this way, then the A/Ds will track. A good start would be 12V in to a 2K resistor, the other end of the 2K to Vref and that junction through a 1K resistor to GND. Put a 10uF capacitor across the 1K for a noise filter, and a diode across the 2K (cathode to the +12V end). This diode will prevent the cap from discharging into the PIC Vref pin under fault conditions. The values given will put 4V (nom) on Vref.

Once you have calibrated your unit, save your critical variables in the chip's EEPROM. Every time you power up, read those variables and have your program act accordingly.

lew247
- 20th December 2009, 23:15
Maybe I didn't explain it good enough, or maybe I just don't understand what you mean.

a hypothetical scenario - Think of a pic processor with a variable resistor attached, at 4 stages in the sweep from one end of the variable resistor, I need to take a reading of the resistance and store that vbalue in the pic in an eeprom location.

Now everytime the resistor is turned varying the resistance, once the pic sensed the already measuered stored in eeprom values it acts and lights an led for every position.

The main problem other than not having a clue how to go about getting the pic to "recogince and store the initial 4 values, is every pic will be attached to a different variable resistor with no idea what the values are before it is turned on, and at 4 stages the pic must take a reading and store that resistance and again act on that reading tthe next and everytime the resistance is varied, so for example if the resistor is turned 1/4 turn it measures that value and stores it, next time the resistor is turned the pic knows when that preset value is reached, ie when the resistor is in exactly the same position, and lights an led.

Hope that made some sort of sense, If it was a case of one variable resistor with a known value it might be easier, but the variable resistors could be any initial value, which is why the 4 preset values need to be stored in the pic by pressing a button when needed, again ie say the variable resistor is turned 1/4 turn the button pressed and the value of the resistance stored.

Something like that anyway.

Charles Linquis
- 21st December 2009, 01:06
You don't mention how the variable resistors are connected. If one end goes to 12V and the other end goes to GND, then as the wiper is rotated, the output will be 0-12V. You can divide that down and convert the voltage with the A/D in the PIC.

You can use a pushbutton on one of the other pins.

Set the variable resistor to the 1/4 position and push the button. Take an A/D reading and store the value in an EEPROM location. Advance a counter and set the variable resistor to the 1/2 position. Push the button again to take an A/D reading and write to the EEPROM location set by the counter. Advance the counter. Set the variable resistor to the 3/4 position. Push the button. Save the value.
As a last step, write a known value to an EEPROM location to indicate that the part has been calibrated. On power up read that location. If it has already been calibrated, skip the calibration step and run normally.