Pages: [1]   Go Down
Author Topic: best way to communicate between 2+ standalone ATMEGA328s?  (Read 669 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm making a methanol injection controller for my car.  I need to split the analog reads of 6 sensors (Manifold Absolute Pressure sensor, Throttle Position Sensor, knock sensor, wide-band O2, methanol level, and a trim adjustment pot) between at least 2 chips.  60mS of delay for the analog to digital converter each time through the loop is a bit high for injector pulses of as little as 5mS.  I would gladly use 6 chips if possible, where the master chip would measure the methanol level only until the injector was commanded on, at that point it would switch to a formula to estimate the level and a level switch would act as a safety in case of a leak.  At about .7Gs from 0-75 MPH, a level sensor becomes very inaccurate anyway, especially with a manual transmission that has 2 shifts in that range.  I've got 14 PSI boost and 10:1 compression with the goal of running 89 octane (R+M/2) pump gas, so methanol delivery will be critical to not sending a rod through the side of the block.  I'd like to get this perfect on the first try, I do have a race engine built and ready to drop in if I fail (I'm replacing the current engine before summer anyway), but I'd like to have this engine intact to build up so I have a spare.

My first thought was to daisy-chain the chips (tx1 --> rx2/tx2 --> rx3/tx3 --> ... -->rx1) where the first chip would send a request and the subsequent chips would add their data to an array and pass that along to the next chip with a request for that chip's data to be sent to the next chip and so on until the master chip has all 5 of the other chips readings.  Unless I've missed something, I can only send 8 bits at a time, making this idea seem... less good (at best)... maybe impossible.  I'd also like to transmit/receive longs, as the .02V resolution of 8 bits is a bit low (no pun intended) for the MAP and O2 sensors.  I think it would work with 8-bit, but if it's not a ton more work I'd really like to take advantage of the full capabilities.  I know very little about serial communication, so "pretend" you're talking to a complete noob smiley

Thanks,
Jason
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8531
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The daisy-chain scheme you mention is well known and there is no practical limit to the number of bytes you can send, whether or not it's what you need I'm not sure.

Quote
60mS of delay for the analog to digital converter each time through the loop
Where does this come from?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is my understanding that the analog to digital to converter needs 10mS between reads or the reading can be influenced by the last reading, 6 sensors 60mS.  Is that incorrect?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is my understanding that the analog to digital to converter needs 10mS between reads or the reading can be influenced by the last reading, 6 sensors 60mS.  Is that incorrect?

Yes, that is incorrect.

Lefty
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18815
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Unless I've missed something, I can only send 8 bits at a time, making this idea seem... less good (at best)... maybe impossible. 

Why only 8 bits? Just send 2 bytes, that gives you 16 bits.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18815
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to amplify, each chip can send some numbers followed by a marker (eg. newline). The next chip receives everything until it gets the newline, discards that, adds its stuff and resends. Of course, you would need to send in ASCII not binary for that to work. Alternatively the first chip sends 2 bytes, which the second chip waits for. The second chip adds 2, giving four, so the third chip looks for 4 bytes and so on.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18815
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And if I was doing it I would allow for noise. So something like:

* first chip sends a "magic marker" being something like 0xFF 0xFE 0x55 or something. Other chips check that their received data starts with that and if not, discards it.

* each chip sends as many bytes as you want (2, 3, 4) and then their 1's complement. That is a sort of validity check.

* the final chip checks the magic marker, and checks that the numbers and their 1's complements agree. That rules out spikes or noise, more or less.

eg.


Code:
unsigned int reading = whatever ();
byte a = reading >> 8;  // high-order byte
byte b = reading & 0xFF; // low-order byte
byte ax = a ^ 0xFF;  // complement
byte bx = b ^ 0xFF;  // complement

Serial.print ("\FF\FE\55");  // magic marker
Serial.print (a);   // msb
Serial.print (b);   // lsb
Serial.print (ax);  // check byte
Serial.print (bx);  // check byte


Logged


Pages: [1]   Go Up
Jump to: