Starting a new build

Started by Chewy1576, February 12, 2018, 07:34:30 PM

hakcenter

LOL Linx, what a nightmare. Never ever ever update, LOL

And keep every version of every install different, and you're pretty much good to go.

I did a lot of automation for bottling companies with a good friend of mine. Ladder logic is so simple though.

There was times, hey you know if we fix this program.. you know we own the machine at this point right? :)
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Chewy1576

#61
Yep!!! I see that day in and day out. I'm part of a group of 11 software/controls engineers, and there are a few other groups throughout the plant with the same responsibilities/access we do. So if we or they change a program, they take it over. Makes revision control a nightmare, especially for HMI's.

Anyway, I ordered a few breadboards, a bundle of jumpers, a kit of misc headers, and a TXB0104 board for the MAX31855 thermocouple amp. I've read that the MAX31855 will work with 5V, but won't last long. The TXB0104 will drop the voltage to 3.3V to get a lot more life out of it. I also ordered the 351VE connector parts from Mouser, thank you for the project list link!

Rx7man

I'm not very fond of the MAX31855.. never was able to get them working right,.. maybe the chinese board they were on were bad beyond what I saw and fixed on them .... In theory they should be simpler, no initialization requirements is kinda
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

Making some progress...

I ended up ordering another LCD with an I2C interface board already soldered on. 4 wires to the Pro Mini (VCC, GND, SDA, SCL) and it's talking. I'm using the NewLiquidCrystal lib for commands and it seems to be refreshing very smoothly. I programmed some incrementing counters for formatting and testing the display. I'll just write data that comes in over SPI from the Uno to those variables.

I believe I have the SPI interface between the Uno and Pro Mini wired, and I'm working on the coding. Maybe you guys can help - I want to build an array from a long, float, and 2 ints. My idea was to arrange the data into an array of bytes, serialize and transfer the array over SPI, then put the bytes back into the variable types on the other side. Then I'll print them to the LCD with every refresh. I'm sure I'll have to play with transfer and delay timers to make it all function smoothly.

Rx7man

For your array problem, look up Unions.. they can represent any data type on its binary level and convert without any overhead

So a float is 4 bytes long, transferring the information by text would take 10 bytes for 10 digits (plus one for a decimal point).. I can't remember if my syntax is completely correct, but I'll give it a shot off the top of my head.. Only requirement is that all data types are the same length AFAIK



float f1 = 12.345f;
unsigned long int ul1 = 1392487ul;
signed long int      sl1 = -234453l;

union fourbyte{
float f;
long int l;
unsigned long int ul;
byte[4] b;
}

//to use it now
void loop{
fourbyte DataToSend;

DataToSend.f = f1;
SendToDevice(DataToSend);

DataToSend.ul = ul1;
SendToDeveice(DataToSend);

DataToSend.sl = sl1;
SendToDevice(DataToSend);
}

void SendToDevice(fourbyte data){
  for(int i = 0; i<4; i++){
    SomehowSendByte(data.b[i]);
  }
}


I just transfer EVERYTHING as a float so I don't need to keep track of what kind of data type I'm dealing with

At the other end, take your four received data bytes as an array, assign them to the byte subtype of the "fourbyte" and then use the "float" subtype to get the value


Hope that is what you were looking for
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

Yes this does help, I will probably use a union on the master side. The only reason I have a float is so that I can report Actual Vane Position in fractions of 0.50, possibly 0.25. The data I want to send is Turbo Shaft Speed (Long, because it can get above 100k), Vane Position (float), Boost Pressure (int), and EGT (int). I should probably send one or two bytes to use as status bits for displaying things like Turbo Inactive, Actual Operating Mode (Idle, Normal, Cruise, Braking), Manual Vane Control Active, etc. So that's 14 bytes total.

Rx7man

I'd send everything as a float and be done with it..

I'd bet as time goes on you're going to add a lot more stuff to display.. fuel pressure, oil pressure, turbo data feedback, etc

I'd just create a CAN address for each variable and send the data to it, the slave listens for many addresses and handles each one separately
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

K I'll set those variables up as floats and I'll send 4 bytes worth of status bits, to make 5 floats total, 20 bytes. I probably will add fuel pressure, and possibly drive pressure in the future. Everything else I want to monitor I can get on my Scangauge.

So looking into the unique addressing for each variable, I think I can set up different ID/Masks and have individual send commands on the Master for each one. Then on the Slave side, have individual msgavailable commands looking for a data packet on the bus addressed to those ID's, grab the data when available, and write it to where I want it.

On another front, I have the thermocouple amp talking to the Uno over SPI. I don't have a thermocouple yet, so it's just reading NAN. Next will be wiring the Pro Mini and it's CAN board to get them talking, then establishing the CAN bus between them.

Rx7man

there is some data you can get back from the turbo as well.. Drive rate, commanded position, actual position, and temperature.. I think there may be more but I haven't been able to access them
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

What does the drive rate parameter mean? I'm already planning to display actual vane position. Maybe I can show actuator temperature on the same line. Here's a quick video of what I had a few days ago, it's been tweaked a little since then.

Chewy1576

Had to give this a shot before bed...

void C_CANBUS()
{

  union turbo_speed_array { // Create 4 byte array out of Turbo Speed float
    float turbo_speed;
    byte byteTS[4];
  } TS_array;

  union vane_pos_array { // Create 4 byte array out of Vane Position float
    float vane_pos;
    byte byteVP[4];
  } TP_array;
 
  unsigned long Var1_ID = 0x11E1A300; // Msg ID for Turbo Speed & Vane Position = 300000000 DEC
  byte length = 8; // Send length = 8 bytes
  byte data1[] = {TS_array.byteTS[0], TS_array.byteTS[1], TS_array.byteTS[2], TS_array.byteTS[3], TP_array.byteVP[0], TP_array.byteVP[1], TP_array.byteVP[2], TP_array.byteVP[3]}; // Combine Turbo Speed and Vane Position arrays for one send

    CAN1.send (Var1_ID, extID, length, data1);

  union boost_pressure_array { // Create 4 byte array out of Boost Pressure float
    float boost_pressure;
    byte byteBP[4];
  } BP_array;

  union egt_array { // Create 4 byte array out of EGT float
    float egt_float;
    byte byteegt[4];
  } egt_array;
 
  unsigned long Var2_ID = 0x127A3980; // Msg ID for Turbo Speed & Vane Position = 310000000 DEC
  byte data2[] = {BP_array.byteBP[0], BP_array.byteBP[1], BP_array.byteBP[2], BP_array.byteBP[3], egt_array.byteegt[0], egt_array.byteegt[1], egt_array.byteegt[2], egt_array.byteegt[3]}; // Combine Boost Pressure and EGT arrays for one send

    CAN1.send (Var2_ID, extID, length, data2);

}

Rx7man

Make the 4 byte union type first, then make an instance of the type for each application of it

it's just another data type, so after making the type,...

union fourbyte{
float f;
byte b[4];
}

fourbyteunion egt;
fourbyte union boost_pressure;

//then you access the subtype you want within it.

egt.f = 1.234;
boost_pressure.f = 2.345;

Senddata(egt.b); //where Senddata expects a 4 byte array
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Rx7man

Oh, the drive rate is how hard the VGT actuator motor is working, it's an 8 bit signed integer.. so -128 to +127
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

That cleans things up quite a bit...

union fourbyte {
    float f;
    byte b[4];
  };

  fourbyte turbo_speed;
  fourbyte vane_pos;
  fourbyte boost_pressure;
  fourbyte egt;
 
  unsigned long Var1_ID = 0x11E1A300; // Msg ID for Turbo Speed & Vane Position = 300000000 DEC
  byte length = 8; // Send length = 8 bytes
  byte data1[] = {turbo_speed.b[0],turbo_speed.b[1],turbo_speed.b[2],turbo_speed.b[3],vane_pos.b[0],vane_pos.b[1],vane_pos.b[2],vane_pos.b[3]}; // Combine Turbo Speed and Vane Position arrays for one send

    CAN1.send (Var1_ID, extID, length, data1);
   
  unsigned long Var2_ID = 0x127A3980; // Msg ID for Turbo Speed & Vane Position = 310000000 DEC
  byte data2[] = {boost_pressure.b[0],boost_pressure.b[1],boost_pressure.b[2],boost_pressure.b[3],egt.b[0],egt.b[1],egt.b[2],egt.b[3]}; // Combine Boost Pressure and EGT arrays for one send

    CAN1.send (Var2_ID, extID, length, data2);

Rx7man

That does look much better :).. and it works, right?
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles