Planning a DIY Data Acquisition/Engine Controller

Started by dubbleUJay, October 21, 2009, 09:09:03 AM

Previous topic - Next topic

BigGreen

#120
BruceM
I haven't moved on to the picaxe world yet because I use an old MPLab ICD programmer/debugger at home. I'm locked into 16F pics and MPLab ver 6.2, the last version that supported this programmer. I upgraded my monitor to allow the A suffix pics but that's as far as I can go until I spend more $$ and don't see the need. the 16F84 handles the small jobs and the 16F877 can certainly take care of the rest :)
I haven't used Boost C so I can't comment on it. Floating point can be done without the library of course but it takes a few steps to get there.
I mainly use MELabs pic basic pro but also use microchip pic c from time to time, depending on what I want to do. I started with the c but found the basic pro on epay for a song and never looked back. Purist programmers beat on basic but I find it easier to get the job done for the most part. Assembly will make a nice, compact load but takes many steps to get there and is cumbersome to correct errors. I was into the 68HC11 assembly and Z-World dynamic c before I found pic's.
At work I use a borland c++ compiler, LabView and VB.NET

Not to get into that same old pissing contest but the stamp runs half throttle compared to the pic. I have several coworkers that cut their teeth on stamps and they stay with them and that's fine by be. They are set up and rocking so why change. I stay with what I know as well :)  

Dave

BruceM

Bob, your use of IDE cable and hardware is ingenious!  A great design, with all that great hardware and connectors for a song. I'd love to see some pictures.

You have mega wires to play with for your "bus", you can do whatever you need, even dedicated interface to any processor.  Since the distances are short, you probably could do I2C on two wires of your bus, but as you previously suggested, some dedicated signal lines and maybe a TTL serial line pair or two would suffice.  You don't need twisted pair, you're sitting pretty with your IDE "bus".

With that nice mechanical design, no wonder you're ready to add processors!

Bravo, Bob!


BruceM

Thanks for the report, Dave.  I also prefer Basic somewhat over C, myself, because I'm very short term memory impaired now, and can't keep hundreds of lines of code in my head like I once could. It's just a little easier for me to read and keep track of.  I can't swing the price of Microchip's MPlab and Basic, but I really like the look of Swordfish Basic for PICs from England.  It a nice structured basic, full featured.

I'm with you on "go with what you know", too.  Lots of ways to skin the cat, and just getting the job done is the important part. 




BruceM

#123
Thanks for the heads up, Jens.  I saw the post and it sure sounds like support is not there anymore.  Swordfish now smells dead and 3 days old.  There's nothing as frustrating as getting screwed by other peoples software (OPS).

Fortunately there are many options in PIC compilers.


dubbleUJay

#124
OK guys, I've got the temperature code integrated into the "Main Code" (Multiplexer)
I'm now reading and writing to file, the last 6 channels on the Extension Board with LM35 Temperature Sensors converted to Celsius (0-125degC), but its easy to change to Fahrenheit as you know. I still need a circuit for reading up to about 450C for exhaust temps to finish the temperature side of things which will have 2x inputs allocated for it.

The code probably need some work to make it shorter, but I'll leave that for last.
Here's the current code if anyone is interested and if anyone sees a problem or a better way to code something in it. please let me know, I'm learning from this.  ::)
Also let me know if its OK to present the code this way or should I use an attachment ??? I don't wanna "p" anyone off! ;)

/* PC DataLogger(Real-time) & Engine Controller(Stand-alone)
for Micro Co-Generation Systems by dubbleUJay
Forum thread: http://www.microcogen.info/index.php?topic=188.0
Current Status:(v0.23 Alpha)

Hardware:
1x Arduino Duemilanove (ATmega368)
1x Extended Analog Input board (16ch HEF4067BP Multiplexer)

Probes:
6x  TempSensor(LM35or36)         (extApin10-15)  (Beta)
2x  K-type Thermocouple          (extApin8-9)    (Alpha)
1x  AC Volts/Amps/Power          (extApin0&1)    (Alpha)  
1x  Engine RPM Sensor (Opto-???) (extApin7)      (Not Started)
1x  DC Volts/Amps/Power          (extApin2&3)    (Not Started)
2x  Digital Inputs Fuel-/H²O Level               (Not Started)
1x  Oil Pressure Sensor (Maybe)  (extApin6)      (Not Started)

Engine Controller:  (Not Started!!)
1x  Throttle Control Governor               (Not Started)
1x  Digital Output Emergency Shutdown       (Not Started)
*/
//------------------------------------------------------------------------------
//----------------START of: 16 Channel Analog Input Extender--------------------
// (Extended Analog Input pins 0to15 = ExtAin[0] to ExtAin[15])

byte chActive=16;  // The number of channels active.
byte chNumber=0;   // Keep count of the channel number to read.
int currentVal=0;  // Current Value of channel
int ExtAin[15];    // Store 16x Extended Analog Input values in Array here

// Set initial Address Input values for A0 to A3 (bits 1to4)
byte binA0=0;
byte binA1=0;
byte binA2=0;
byte binA3=0;

void setup() { // Setup for Multiplexer

 // Set Digital pins to Outputs
 pinMode(10,OUTPUT);  // (A0 <-> pin10)
 pinMode(11,OUTPUT);  // (A1 <-> pin11)
 pinMode(12,OUTPUT);  // (A2 <-> pin12)
 pinMode(13,OUTPUT);  // (A3 <-> pin13)

 Serial.begin(115200); // Set Serial COMM's to PC
}

void loop() { // Get the Analog Values from Multiplexer

 // Loop through the 16 channels and read each one.
 for (chNumber=0;chNumber<16;chNumber++) { // Create Channel Numbers

   // Generate Address Inputs for HEF4067BP A0 to A3 (pin 10 to 13)
   binA0=(chNumber&1);     // Create 1st bit for Address A0
   binA1=(chNumber&2)>>1;  // Create 2nd bit for Address A1
   binA2=(chNumber&4)>>2;  // Create 3rd bit for Address A2
   binA3=(chNumber&8)>>3;  // Create 4th bit for Address A3

     // Send current Address Inputs to Multiplexer
   digitalWrite(10,binA0);  // Set bitA0 on pin10
   digitalWrite(11,binA1);  // Set bitA1 on pin11
   digitalWrite(12,binA2);  // Set bitA2 on pin12
   digitalWrite(13,binA3);  // Set bitA3 on pin13

     // Read the common I/O pin0 value for current channel
   currentVal=analogRead(0);

   // Write Current Value to Array index position
   ExtAin[chNumber]=currentVal;
 }
 if(chNumber<(15)) {  // Step through all 16 channels until end
 }
 else {        // Step out of loop to next task  
   delay(10); // 1000=1sec
 }
 //--------------END of: 16 Channel Analog Input Extender----------------------
 //----------------------------------------------------------------------------
 //--------------START of: LM35 Temperature Sensors (°C)-----------------------  
 // 2x K-type Thermocouple Devices (<400°C) & 6x LM35 TempSensors(<125°C)
 // (Extended Analog Input pins 0to9 = ExtAin[8] to ExtAin[9])
 // (Extended Analog Input pins 10to15 = ExtAin[10] to ExtAin[15])

 // Code for LM35 Temp Sensor connected to ExtAin[10] to ExtAin[15]
 int tSenLM35=10;   // The Starting LM35 Sensor Number
 int tValue=0;      // Current Value of Temperature Sensor (Celsius)
 int mArrayVal=0;   // Stored Multiplexer array Value
 int tValArray[6];  // Store calculated Temperature values here (Celsius)
 int tV=0;          // Integer for Temperature Value selection

 // Serial Print START-string for GoBetWino
 Serial.print("#S|LM35TEMPS|[");
 Serial.print(" ");
 // Loop through the LM35's & calc the temp from stored values in Mplex Array
 for (tSenLM35=10;tSenLM35<16;tSenLM35++) {  // Create LM35 Xpin numbers

   // Get selected LM35 Sensor value from Multiplexer Array
   mArrayVal=ExtAin[tSenLM35]; // Get stored Multiplexer value
   tValue=(5.0*(mArrayVal)*100.0)/1024.0; // Convert to Celcius
   tValArray[((tSenLM35)-9)] = tValue; // Write LM35 Value to Temp Array

   // Print to serial port  
   Serial.print(tValue,DEC);
   Serial.print("; ");

   if(tSenLM35<(15)) {  // Step through Ext Analog from Xpin10 until end
     // Return Values to zero
     tValue=0;
     mArrayVal=0;
     delay(10); // delay before loop
   }
   else{ // Serial Print END-string for GoBetWino
     Serial.println("]#");
     delay(1000); // Delay before starting over
   }
 } // END of: LM35 Temperature Sensors (°C)
} //------------------------------END of CODE-----------------------------------



Bruce, I need some help with the DC sensing cct please. I've been following the thread by Jedon about scaling from 48-5V and I decided its probably wise to do mine at  the same time as its more or less the same thing. (You know, there where I made a few mistakes with my postings!  ;) )
I'll carry on with the VAac-, RPM- & 0-450C Temp sensor after this one.
I've taken the ccts you presented there and came up with the following diagram to read 0-30Vdc & 0-30Adc.
Its not at all a working model and I just want to know if I'm on the right track for my application please?
I'm probably going to need some help with the calculations for the resistors as well if you have the time please ??? Cct diagram at the bottom.

Thanks to all who's helping here guys, much appreciated!
dubbleUJay
Lister  - AK - CS6/1 - D - G1 - LR1 -
http://tinyurl.com/My-Listers

dubbleUJay

Daryl, I haven't forgotten about the things you wrote a few posts ago, I'm still looking into that. (I've actually printed it out and I'm going to go through it 2night, marking off the ones I didn't think of)
I'm repeating myself about this a lot and I'm sorry for that, but I'm not English speaking and I've got to read stuff you guys write a few time to grasp what you're saying.
My spellchecker is working overtime on this forum as I post!!! ;)

By reading your suggestions quickly, it seems that it's what I'm trying to accomplish exactly.

As soon as I know that I'm doing things the right way with the coding, we can start looking at incorporating more of your very valid points and suggestions.
Because of my ignorance with the coding, I'm not sure if I'm following the right paths? I'll hate to get to the end and have to rewrite the stuff!
As it is at the moment, I'm battling to get the flow of things, although I had to change most of the code I got from other places, they just gave me a general idea of how to do it.
I probably need to make a flow chart of this whole thing and should have done it in the beginning, but I wasn't sure where to start.
If you have done something like this before (with your experience with your work as you mentioned?) can you maybe draw a flowchart of your ideas and tell me where the section I have at the moment would fit in please? A picture tells a....... you know the story!  ;)

dubbleUJay (I do know how to spell double though! ::) )
dubbleUJay
Lister  - AK - CS6/1 - D - G1 - LR1 -
http://tinyurl.com/My-Listers

BruceM

That would be great if Daryl could help WJ with a top down structure for his code.  I'm in the midst of new hardware/software checkout for my BBCC project.

I'll check out your schematic within a day or so, WJ.  Sure, glad to help you get your values right.

Sorry,  guys about some of my heavy handed edits and deletes on the voltage scaler thread. I just whacked anything that I thought was not particularly helpful or was misleading to a later reader, and squashed together some of what would.  I need to cut out some of my own posts too, to simplify it, but have been too busy.  I'll try to do better. I'm often tactless, and especially when correcting errors, I'm bad.





Crumpite

Quote from: dubbleUJay on December 03, 2009, 09:58:47 AM
Daryl, I haven't forgotten about the things you wrote a few posts ago, I'm still looking into that. (I've actually printed it out and I'm going to go through it 2night, marking off the ones I didn't think of)
I'm repeating myself about this a lot and I'm sorry for that, but I'm not English speaking and I've got to read stuff you guys write a few time to grasp what you're saying.
My spellchecker is working overtime on this forum as I post!!! ;)

By reading your suggestions quickly, it seems that it's what I'm trying to accomplish exactly.

As soon as I know that I'm doing things the right way with the coding, we can start looking at incorporating more of your very valid points and suggestions.
Because of my ignorance with the coding, I'm not sure if I'm following the right paths? I'll hate to get to the end and have to rewrite the stuff!
As it is at the moment, I'm battling to get the flow of things, although I had to change most of the code I got from other places, they just gave me a general idea of how to do it.
I probably need to make a flow chart of this whole thing and should have done it in the beginning, but I wasn't sure where to start.
If you have done something like this before (with your experience with your work as you mentioned?) can you maybe draw a flowchart of your ideas and tell me where the section I have at the moment would fit in please? A picture tells a....... you know the story!  ;)

dubbleUJay (I do know how to spell double though! ::) )

Your english is better than most Americans, no joke... And I have to read through the stuff on this list several times too - the information is so condensed it's hard to absorb all of the meaning in one read though.

Yes, a flow chart might be a good idea - but I've  been watching and waiting and reading all of the posts to get a good idea of what folks are looking for in this area.
(and I'm not good at drawing stuff - maybe I can find some flowcharting software somewhere...  :)

I'm envisioning a master/slave architecture for the whole system.

I'm beginning to think that your choice of the Arduino for the DAQ work is an excellent idea.
The hardware is reasonably inexpensive and has many options for every type of I/O needed. (your Analog multiplexer board is genius - it's just what's needed for this application.)
The software is less impressive, but is simple enough and is extensible enough to do the trick.
The Picaxe software just isn't powerful enough to do this task, IMHO.
(sure you can use compilers and such, but not everyone can afford to buy one and then there is the learning curve and *another* language and IDE to learn)
The Arduino has enough options to act as a "master" that can communicate to the "slaves" that handle different tasks than data acquisition.

The master can collect data that isn't needed for control, and poll the slaves for their respective data and tell them what to do if needed.
I can see Picaxe chips as perfect slaves. They are cheap enough to throw away if you blow one during development work.
(I've found that the 'closer' to the actual hardware any electronics are, the more hardy they need to be to survive in day to day work)
The slaves will do all the actual control work. They will connect to all necessary sensors (and no more, it's a design philosophy) and run all actuators needed.
All of the control code will be in the slave, with just enough extra to talk to the master to transfer it's information (sensor readings, actuator positions, etc.) to the master.

All of this sounds terribly complicated, but you're already contemplating doing most of it.

A mind picture:

You sit at your easychair and hear the lister's exhaust note change - you wonder what caused it.
You walk over to your computer and call up the status screen that's talking to your Arduino and check it out.
The real-time graph of power consumption looks ok, so you switch to the detail screen and see that the hot water heater has just turned on and that you're drawing a little too much power.
You click on the little button on the screen connected to your hot water heater system to shut it down.
It sends a command to the Arduino which says to cut power to the hot water system. It then sends a command to the Picaxe that's controlling the load managment.
It sets one of it's output bits low and the relay drops out.
Meanwhile the Arduino is still scanning it's data points and talking to the two Picaxe systems that control the engine management and load management.
The load management picaxe does it's routine data squirt to the Arduino when polled and the Arduino in turn sends it's info back to the computer in the house.
Which then shows that the water heater relay is off and changes the color of the button you just clicked. And now the power draw is more reasonable and you go back to your coffee...

By breaking the big task down to little pieces the whole system becomes manageable. You can install just a part of it and add more later as needed without having to redesign the entire system.
You can blow a fuse on any one part of the system, and the rest just keep doing what they've been told to do.

This is the way the big boys do it, but again, you don't need to do all or even most of it.
The advantage is an extensible system where you can reuse most of the code. Each section can be changed and reprogrammed without affecting others.
Different people can program different parts and as long as they agree on the protocol for intercommunication they can all play nice together.

Again, it's probably a pipe dream, but it's better to have some kind of framework in mind when you start out on a big project.

So, go ahead and beat me up, I've got big shoulders.  ;D
Daryl the Dreamer



Crumpite

Quote from: BruceM on December 03, 2009, 11:38:25 AM
That would be great if Daryl could help WJ with a top down structure for his code.  I'm in the midst of new hardware/software checkout for my BBCC project.

I'll check out your schematic within a day or so, WJ.  Sure, glad to help you get your values right.

Sorry,  guys about some of my heavy handed edits and deletes on the voltage scaler thread. I just whacked anything that I thought was not particularly helpful or was misleading to a later reader, and squashed together some of what would.  I need to cut out some of my own posts too, to simplify it, but have been too busy.  I'll try to do better. I'm often tactless, and especially when correcting errors, I'm bad.


You do a great job of moderating, BruceM !
I'm a moderator myself, it's a hard job at times trying to balance everything...

Keep it up,
Daryl

Crumpite

Folks,

Another thing I forgot to talk about is isolation.

Almost always when working on several pieces of equipment - engine, generator, pumps, battery bank, inverter, etc. you'll find that there is a voltage difference between them.
Sometimes AC, sometimes DC, most often a mix of both...
This is due to leakages in insulation, corrosion, capacitive induced voltages, magnetic coupling, and all sorts of ways you will have never heard of till you try to get things to talk together.

If you try hooking the grounds together so you can use microprocessor level signals to communicate, you'll find it pretty difficult at times.
You can try all sorts of methods of grounding and isolating your equipment, and still tear your little remaining hair out trying to get rid of noise that interferes with your signal.
If you improperly inter-tie your equipment, you also may get what's called a ground loop - a circulating current between the ground points that can baffle you.
This usually shows up as bad noise on your sensors, although I've seen it so bad that the wires that tied each D/A board to each other to supply a common ground would simply melt for no good reason...

I think you folks were discussing how another guys project kept burning up isolation amps - been there and done that !

BruceM's idea of using opto-isolated RS-232 communications is something that can save your bacon and sanity.

The idea is to let each little Picaxe or Adrundo float at it's own voltage where it's happy, and let an optoisolater take care of the problem.

The signal is carried by a changing *current* rather than a voltage. Most voltage signaling systems are pretty high impedance, which means that it doesn't take much to induce interference.
Now a current loop (as they are called) is a low impedance system - it takes a nearby lightning strike to cause a current loop to fail.

So your output pin of your microprocessor of choice drives a transistor on and off, which switches a 20ma. current on and off.
(this is the industry standard current, this method is used in factories all over the world and has been used for decades due to it's robust nature)
Back at where the signal is going (which can be miles), that 20ma current turns an led on and off, which in turn makes a phototransistor switch a voltage signal into your second micro's I/O pin.
They make nice little four pin IC's that handle everything - optoisolators.

You can easily have a Picaxe sitting at hundreds of volts to ground and still talk to another unit that's grounded or hot in some other fashion.

http://en.wikipedia.org/wiki/Current_loop

If you use this type of topology, separate masters and slaves communicating via current loops, you can save yourself time and trouble by having communications that work the first time and don't die every time the humidity gets high in the generator house or battery area.

These are just a few more thoughts on the "DIY Data Acquisition/Engine Controller".
We might not ever need some of these ideas, but being aware of potential problems never hurts.
Daryl




Crumpite

Quote from: BruceM on December 03, 2009, 11:38:25 AM
That would be great if Daryl could help WJ with a top down structure for his code.  I'm in the midst of new hardware/software checkout for my BBCC project.

I'll check out your schematic within a day or so, WJ.  Sure, glad to help you get your values right.


I'm looking at some flowcharting software right now - I'll be trying to put together a "top down structure" together today or tomorrow (I'm a bit busy myself right now  :)

Now where's my paper and pencil...
Daryl

BruceM

#131
Good that you mentioned opto-isolation, Daryl, and that was a good explanation.  I use it for anything with a wire over a few feet. It makes sense to  bullet proof a homebrew system; the extra cost is insignificant, an the time savings in not having to "chase gremlins" makes life easier.  

For very long runs, hundreds of feet, 10ma is normally plenty, for 2 dozen feet, 2ma works.  But I'm always trying to save every ma, as it's all off grid, battery powered. As Daryl says, 20ma current loop is an old standard from back when I was banging a teletype with paper tape.  

For example, my Battery bank charge controller (BBCC)has a triple solid state relay for adjusting PV charge current. The schematic link is below. The controller can pick which series PV tap (of 2) as well as a big power resistor. (No PWM crap on MY clean lighting DC.)  It's a  good case for an opto-isolator, even though only a few feet away, because it's switching up to 210VDC, and any current switching is also glitch inducing...and really should be optically isolated from the processor.

 I usually use Panasonic's PC123 opto-isolator.  One ma will just operate it with a high impedance ouput, new, so 2ma is a safe minimum drive current.  They're cheap, fast, low power.  On the PV SS relays, the PC123's drive 1411N's, a micropower mosfet gate drivers.

Similar story (6 total opto-isolated controls total) my AC battery charger; there in addition to 3 of the PC123's for a zero-cross capacitor switcher board I designed, but  I also use 3 of the new opto-mos by Panasonic.  They are opto-isolators that can switch even 240VAC, up to 150ma, plenty for an AC relay coil. They are really sweet- no EMI like the old, nasty opto-triacs.  So for about 3ma of current, you can cleanly switch an AC coil relay or contactor.

Likewise, signals between the well house, where the BBCC resides with the batteries , and the "House of Lister", are 80 feet away, on a separate small PV/battery, and are all opto-isolated.  And the signals/serial data to the shop, about 400ft. I use CAT5 cable for the opto-isolated signal; with a current loop on twisted pair, you've got a very solid link, even if you reduce the current drive.  The PC123's are about 50 cents each, as I recall.

One last tip before I sign off tonight-  I just finished a bench test "fly off" of 7- 500ma and 1A low drop out (LDO) linear regulators; they were all direct pin replacements for a 7805 , 5V regulator. A conventional 7805 will draw as much as 6 or 7 ma even with no load. The current to ground then increases with load.  Since the LDO regulators are designed for battery systems, they draw much less;  typically between 0.15 and 1 ma, with no load, more with load. It's only important for things that are constantly on, drawing your battery down.  LDO's don't have as good regulation, I was not happy with the 0.3mv of noise that was common in many. Some are also unstable with ceramic capacitors (too low ESR for near the regulator).

The hands down winner: ST's  LF50AB.  It has good regulation, 0.1mv of noise, and is perfectly happy with any capacitance (ceramics OK) on the output. The quiescent current is about 0.5 ma, a good compromise for getting better output regulation.  


dubbleUJay

Wow Daryl, you've given me a lot of info to ponder over a few times! ;)

I would think that we should 1st agree on hardware as you said, I'm biased towards ATmega 'cos I've got one and haven't used PICaxe.

Just a few thing about the Arduino that I've found of interest so far:
1) Some people has taken microSD cards and used that for storage memory.
2) This guy has Arduino nodes&hubs with input onboard- http://news.jeelabs.org/projects/
3) Sensors and Extension Boards- http://www.seeedstudio.com/depot/

There is a lot more on these sites that meets the eye, scratch around a bit, particularly the JeeLabs site!
If one looks hard enough, between the 2 sites one should be able to build a whole home automation system IMHO!
Most of the above is open source & the PCB layouts are available.

The multiplexer inputs can just as well be extended to 4x16=64 analog inputs if we need it!

I 2nd the RS232 comms and there is a Arduino board with a serial port available, although I would rather use 485 for distance, but would that be a problem with opto-coupled connections?
I have at least one application where I need wireless +/-300m, my water-well is across a field from my place.
I've dealt with earth-loops before and know what a pain they can be!

I'll keep myself busy with the sensors in the meantime until we have a direction to agree upon, they should be applicable in any we chose I think.  ;)
Wilhelm
dubbleUJay
Lister  - AK - CS6/1 - D - G1 - LR1 -
http://tinyurl.com/My-Listers

BruceM

#133
http://www.rs485.com/rs485spec.html

WJ,
This should help you understand the various ways to get serial data around.

Optically isolated current loop is a nice solution, as it solves the distant, common ground problem.  Lightning in the area causes big shifts in grounds, that fry non-isolated systems.  485 is just differentially driven, not isolated.

I'm looking forward to see what Daryl and you come up with!

Best Wishes,
Bruce

dubbleUJay

Thank you Bruce, I've used 232 to 485 converters before on CCTV PTZ control to acquire the necessary distance, from there the little knowledge I have on them.

I can visualize this project in my head as I've looked at home automation systems before using the CAN-bus with "Star & Nodes" as in the CARACA project which didn't seem to get to far.
dubbleUJay
Lister  - AK - CS6/1 - D - G1 - LR1 -
http://tinyurl.com/My-Listers