mega squirt code problem

Started by 65fpvmustang, January 05, 2016, 07:01:33 PM

65fpvmustang

i believe the 0x02 is not correct. If someone would be so kind to tell me what to change. I don't know much about code. I'm just not sure if I should change all3 0x02 to 0x01 or something else.


if (ram5.can_bcast2 & 0x02) {
/* holset HE351VE VGT turbo and a wastegate
29bit CAN message 0x0cffc600
8 bytes
D0 = 0 - 0xff for how far open the vanes should be. 0xff is all the way open.
D1 = 0x02
D2 = 0x01
D3 = 0xff
D4 = 0xff
D5 = 0xff
D6 = 0xff
D7 = 0xff
----------------------
*/
data[0] = (outpc.boostduty * 255U) / 100U;
data[1] = 0x02;
data[2] = 0x01;
data[3] = 0xff;
data[4] = 0xff;
data[5] = 0xff;
data[6] = 0xff;
data[7] = 0xff;
send_can29bit(0x0cffc600, data, 8);
}

hakcenter


  byte lo_byte = lowByte(final_vane_position);
  byte hi_byte = highByte(final_vane_position);
  byte data[] = { lo_byte, hi_byte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // data message with an added counter
  // data[2] = 0x02 for recalibrating gearbox


final_vane_position = 500

lo_byte = 0x01
hi_byte = 0xF4

//

final_vane_position = 750

lo_byte = 0x02
hi_byte = 0xEE

The first 2 bytes in the can message, are low and high. Hope that makes a little sense. 255 values isn't enough, so to get from 0 to 1000, you need 4 low bytes, 0 = 0 - 255 range, 1 = 256 - 510, 2 = 511 - 765, 3 = 766 - 1020.

Make sense ?
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.

65fpvmustang

no but I'll keep looking at it tell it does

65fpvmustang

ok so i get the low byte but don't understand why the high byte goes from 0xf4 to 0xEE.

65fpvmustang

Just wanted to say thankyou. I'm sure it will make more sense in the morning.

Rx7man

Quote from: hakcenter on January 05, 2016, 09:20:06 PM

The first 2 bytes in the can message, are low and high. Hope that makes a little sense. 255 values isn't enough, so to get from 0 to 1000,  you need 4 lowbytes, 0 = 0 - 255 range, 1 = 256 - 510, 2 = 511 - 765, 3 = 766 - 1020.

Make sense ?
the bolded part is wrongly worded
you need to hold a value from 0-1000, but a byte (8 bits) holds values from 0-255... in order to hold from 0-1000, you need 10 bits, which actually works out to 0-1023.. since you can't use just part of a byte to get the 10 bits, you need 2 bytes, or 16 bits

So to hold a value of 1000, in binary that is the high byte = 0000,0011(decimal 4) and the low byte is 1110,1000 (decimal 232).

forgive me if I'm simplifying too much, I don't know your programming background... but each digit in binary really works in a similar way to the decimal system... except instead of each place being a multiple of 10, it's a multiple of 2.
If we invented a 'decimal byte' that held numbers from 0-99 it would be the same idea.. we need 2 of them to define 0-1000, the high one would be 10, and the low one would be 00.. put them together to make 1000

Going back to ordinary byte, the high byte is how many multiples of 256 to add to the low byte... 0000,0011 is 3 in decimal, so 3x256 = 768, the low byte contains 1110,1000 or 232 in decimal, so 768 +232 = 1000

You can extract the high byte and low bytes for a number mathematically

For the high byte, you use integer division (basically discard any decimal points)... so 1000/256 = 3.90625 or just 3 (0000,0011 in binary)

For the low byte you can do it 2 ways
The first (better) way is to take the modulus (remainder division).. so 1000 modulus 256 = 232 or 1110,1000 in binary
The second (may make more sense to someone starting out) is to multiply the high byte by 255, and subtract this from the value you want.. so 1000-(3*256) = 1000-768 = 232 once again

I do believe Arduino C has some functions specifically for this called highbyte and lowbyte, but I wanted to show the math behind it, and am not sure if this applies to megasquirt, so it's there if you need it.

Hope this helps a little, Hakcenter is more versed with the actual sending of the data, so I'll let him cover that
'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

65fpvmustang

this makes since thank you. but i got more reading to do on binary

The second (may make more sense to someone starting out) is to multiply the high byte by 255, and subtract this from the value you want.. so 1000-(3*256) = 1000-768 = 232 once again

I watch alot of g code at work but. but as far as arduino programming thats all new within the last few months.

thank you

65fpvmustang

so looking at ms code again the D0 and D1 should be where the low byte and high byte are sent?
    }

    if (ram5.can_bcast2 & 0x02) {
        /* holset HE351VE VGT turbo and a wastegate
        29bit CAN message 0x0cffc600
        8 bytes
        D0 = 0 - 0xff for how far open the vanes should be. 0xff is all the way open.
        D1 = 0x02
        D2 = 0x01
        D3 = 0xff
        D4 = 0xff
        D5 = 0xff
        D6 = 0xff
        D7 = 0xff
        ----------------------
        */
        data[0] = (outpc.boostduty * 255U) / 100U;
        data[1] = 0x02;
        data[2] = 0x01;
        data[3] = 0xff;
        data[4] = 0xff;
        data[5] = 0xff;
        data[6] = 0xff;
        data[7] = 0xff;
        send_can29bit(0x0cffc600, data, 8 ) ;
    }

With my very limited understanding I'm worried the D1 or data1=0x02 is causing vgt to re calibrate.

byte lo_byte = lowByte(final_vane_position);
  byte hi_byte = highByte(final_vane_position);
  byte data[] = { lo_byte, hi_byte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // data message with an added counter
  // data[2] = 0x02 for recalibrating gearbox

hakcenter

#8
I think the reason you're not seeing why 0xF4 / 0xEE, is you're not looking into it in context. I'll try to write this out better, pretty sure I swapped low and high byte thou.

The first 2 bytes in the canbus data send, is for all purposes an INT, don't try to think of them as 2 separate bytes.

An int, is 0-65535, or -32768 to 32767, value range.
A byte however, is 0-255

So...
0x00FF = 255
0x01FF = 511
0x02FF = 767


byte data[] = { lo_byte, hi_byte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };


So for position 511, it would be
byte data[] = { 0xff, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

So for position 255, it would be
byte data[] = { 0xff, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

Make more sense ?

For recalibrating...


byte data[] = { lo_byte, hi_byte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// data[2] = 0x02 for recalibrating gearbox

data[0] is lo_byte
data[1] is hi_byte
data[2] is 0x01, which is the one you would swap to 0x02 if you wanted to recalibrate the box
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.

Rx7man

Yes, you need to look at the position of the 0x02 is in... it only recalibrates the gearbox if it's in the 3rd (data[2]) position.. where you typically have 0x01

Here's what I use.. it's pretty much the same as what hakcenter posted (because I got it from him), but it's the whole method instead of a snippet


void SendToVGT(int Position){

byte lo_byte = lowByte(Position);
byte hi_byte = highByte(Position);

byte data[] = { lo_byte, hi_byte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // data message with an added counter

CAN1.send (VGTaddress, extID, 8, data);
}
'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

65fpvmustang

 i think i understand the high byte. but on low byte i get lost lost i don't understand how oxff could = 255

byte data[511] = { 0xff, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
byte data[511] ={255 + 256, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

byte data[767] = { 0xff, 0x02, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
byte data[767] ={255 + 512, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

Quote
So for position 511, it would be
byte data[] = { 0xff, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

So for position 255, it would be
byte data[] = { 0xff, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };


65fpvmustang


65fpvmustang

ok i understand what FF is i did not understand that letters were used as numbers.
Dam that took all day to understand.

Rx7man

you got a major problem..
data[511] is an array with 511 elements in it, ditto for data[767]

int data[] = {1,2,3,4,5};
//is the same as writing it out
int data[5];
data[0] = 1;
data[1] = 2;
//etc..
data[4] = 5;



For number systems.. hexadecimal is just a shorter way of writing binary... each hexadecimal digit standing for 4 binary digits
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
8 = 1000
etc
10 = 1010
A = 1011
B = 1100
etc
F = 1111
etc
10 = 0001,0000
11 = 0001,0001
AF = 1011,1111
So, 0xFF is binary 1111,1111

so just as decimal 99 is the largest value you can hold with 2 digits in decimal, 0xFF (255 decimal, 1111,1111 binary) is the largest value you can hold with 2 hexadecimal digits, or 8 binary digits.. any more and you're going to need another placeholder, hence the need for a high byte


Quotebyte data[511] ={255 + 256, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
I don't quite understand what you're trying to do here.. I've already covered how the first part is wrong
'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

65fpvmustang

After final under standing the FF this is where im at. Like i said don't know crap about code.

    if (ram5.can_bcast2 & 0x02) {
    /* holset HE351VE VGT turbo and a wastegate
    29bit CAN message 0x0cffc600
    8 bytes
    D0 = 0 - 0xff for how far open the vanes should be. 1000 is all the way open.
    D1 = 0 - 0x03
    D2 = 0x01
    D3 = 0xff
    D4 = 0xff
    D5 = 0xff
    D6 = 0xff
    D7 = 0xff
    ----------------------
    */
    val=outpc.boostduty * 10
    data[0] =(unsigned char)(val & 0xff); //byte 1 = low_byte;
    data[1] =(unsigned char)(val >> 8);   //byte 2 = hi_byte;
    data[2] = 0x01;
    data[3] = 0xff;
    data[4] = 0xff;
    data[5] = 0xff;
    data[6] = 0xff;
    data[7] = 0xff;
    send_can29bit(0x0cffc600, data, 8);
    }