Main Menu

My life, My coding

Started by Rx7man, May 27, 2015, 09:09:36 AM

Rx7man

Well, I've been doing a serious rewrite of the program.. changing many things from functions that return a value to methods that modify one in the hopes I can speed everything up.. I think I rewrote most of it twice or thrice before I was content with it, and I am not done yet.. I'm hoping I didn't totally break it (it compiles, and I don't think I changed the logic.. I'll find out)... I haven't yet implemented the EEPROM parameter saving/loading, but all my efforts so far have been to make that part of it much easier.
So far, all my modifiers, inputs, etc have changed to floating point, and they're all in 1 global array which is indexed by a named enumerator... I have a little more work to do on that side of it, but when I'm done it'll be much easier to transfer them all over the serial port... about 1-200 bytes of data should transfer ALL parameters to the Pi or Laptop.
At this point, I'm looking at the following
1 array for ALL the running parameters.. probably about 30 or so, at 4 bytes each that's 120 bytes
1 array for each 'map'.. those are 'byte' type, so again it'll be right around 100 bytes each for a 10x10 map which more than plenty
1 array for all the inputs
1 array for all the compensators and function outputs.

I will put a small toggle switch on the box that determines at bootup time whether to read the data from EEPROM or just go with what's hard-coded (might be handy to have something to fall back on)
'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

Well.. broke another bike today.. this time I know it wasn't my fault and can prove it.  I did a bit of an excessive wheelie.. nice soft dirt, and the bike laid over and quit.. that was all she wrote, she was nearly seized.. I managed to roll it over and it didn't sound good at all.. it sounded like a valve was hitting the piston lightly... then I had it in gear and there was no way to move it even with the clutch disengaged, so I knew it wasn't in the top end.
Take it apart, and found that a part of the decompression lever inside had been broken off, there's no way this breaks off except excessive force during assembly (kinda like you gotta line up the dowel pins on the bell housing before cranking it in).. and the piece that had broken off went through the gear between the crank and clutch, mangling it pretty good.
So I tore my old bike apart and stole the parts I needed, turns out the crankshaft got a little bit of a tweak too.. not a whole lot, but enough to cause gear whine... Oh well.. I'll run it this way until it blows up... I know where this engine was rebuilt, and despite warranty being out of the question, I'm probably going to give them a piece of my mind... there were all sorts of bolts that didn't get tightened either... rocker pivots, exhaust studs, valve covers... it was a screwup from start to finish.
'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

Haven't posted much about farm life these days.. got 12 calves and probably will have another by morning... the watched pot never boils.
They're a fun little posse, a whole whack of attention whores, all of them come up to me and lick my boot laces, pull on my shirt tails, etc.. it's a fun time of year, and there's nothing quite like it.. definitely feels like spring.
'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

I've been doing some more coding, putting together a single library that does everything.. CAN, MAX31856, etc all in one.. so far so good.

I need to quit fiddling with the logic of my code so I can keep a tune... I keep doing stuff that kinda require retuning.. on the other hand, I'm getting better at it.

Got some more thermocouple probes in, I think some have longer wires which I need to get to the air horn.  At the price of them I'm glad i picked up a pile.

Not everything around here as been rosey though.. Lost a calf on Monday, had to get the vet out to do a ceasarian, and I got the bill for that.. OUCH.. $966.. would have hurt a little less if I had a live calf.  Momma is doing alright though, and the rest of the calves are growing like weeds (they gain weight at a rate of 4-5 lbs per day right now), and they're a really friendly bunch.. well.. they're just plain attention whores actually!
'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

Here's a couple pics.. First one is infatuated with my camera strap.. just had to chew on it.. Second one is taking his first steps.. he's about 20 minutes old
'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

Sooo.. Had a bit a rough spell with the cows.. One of the first time calvers needed a cesarian,.. Lost the calf and it cost me $1000.. Cow is doing well at least, despite a rather huge scar.  The rest of the calves are doing well.. they're gaining about 4 lbs of weight a day, the heaviest is over 200 lbs, and the little guy pictured above is about 150 lbs already... They're all full of piss and vinegar, playing every evening before bedtime, and mobbing me when I go say hello.

The truck, well, I'm getting things done slowly... tuning is coming along, I'm no longer drastically changing the curves, but it's in little increments now here and there... Haven't done anything with the Raspberry pi yet, it seems like a steep enough learning curve to do anything with it that it's going to wait until winter time unless there's no farm work to be done (that absolutely will not happen!).. Still trying to figure out what method is best to transfer data over serial so I do that work once and do it right, and it's modular enough to accommodate new features. 
I have to do some more tuning to the backpressure compensation, it's currently set to open up when drive pressure exceeds compressor pressure by 15PSI.. I also have to work on the pressure setpoints, but that's proving much harder than anticipated... it would really help spoolup once I got it figured out though.  I'm having a little bit of trouble not having it 'hunt' for the right pressure, so I'll probably have to add a deadband to it, as well as perhaps factor in turbine speed (or at least turbine acceleration), or scrap the whole idea of pressure control and do it exclusively by shaft speed.  Another option is to make a 3D map where it reads the position from a combination of engine RPM, TPS and current boost level, but that will quickly bloat memory usage something fierce.. it's currently 100 bytes for a 2D map, if I have a 3rd dimension of 10 levels that's 1KB, or half my EEPROM, and it'll add a TON of tuning of course, which doesn't sound good to me.
'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

hakcenter

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

Progmem is fine if you're always uploading a sketch from computer or something, i want to be able to change the program and keep settings in eeprom so that I can change the parameters on the fly and have them there next time I reboot it.. From what I have seen, it's not possible to do this with Progmem
'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

hakcenter

progmem stores it in eeprom, you can read it, at +3 more cycles, than ram speed.

You could also write a protocol, to update the progmem areas... ?
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

If that's possible, sure, it sounds good.. except I have no idea how to write that protocol.. Wouldn't it also get erased when you upload a new sketch though?

I think progmem is a good place to store long, static strings, etc,  but if there's any way I can pull it off, I'll keep my engine parameters in EEPROM only.
'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

hakcenter

#160

const PROGMEM  uint16_t charSet[]  = { 65000, 32796, 16843, 10, 11234};

for (k = 0; k < 5; k++)
  {
    displayInt = pgm_read_word_near(charSet + k);
    Serial.println(displayInt);
  }
  Serial.println();


How to use it simply. That'll save you ton's of memory.

If you want to read/write eeprom

int adr = 0;
byte val = 120;
EEPROM.write(addr, val);

byte value = EEPROM.read(adr);
Serial.println(value);


In terms of speed, the flash is only a few cycles slower than SRAM, but the EEPROM is in milliseconds. EEPROM you get like 100,000 writes, flash like 10,000.

You cannot update the flash after you've uploaded the program. You can update the eeprom while the Arduino is up and running, so it's your pick.
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

That was my point.. flash can't be rewritten by the program, and will be overwritten by a new sketch upload if you could.  EEPROM, though slow, doesn't have that problem.. In most cases it will only be reading from EEPROM at boot time, and perhaps writing to it when you change parameters and decide to save it.

If you really want to read/write stuff, put it on an SD card!

IN other news, saw a guy on CF (Dan123dbl) who also lives in BC and has a lil'bb on a first gen... when I go down there I might meet up with him and have a beer and chit chat
'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

hakcenter

Using flash one values that don't change is a great way to save memory though. Who cares if it gets overwritten on a new upload.. every upload you update code anyways, it does the rest.

I saved 500bytes of ram moving just one time strings from Serial.print to useing F().
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, that is what it's well suited for, but engine parameters that you want to change without a laptop (what I've been working on) not so much.
On the Mega you aren't quite as RAM restricted so I haven't bothered much with progmem except for a couple things
'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

Well, things have been quiet around here.. I've been really busy with farm work, also think I fractured a bone on my foot, which doesn't make getting things done any easier or faster...

Also found out my clutch is packing it in, a piece of it was dangling out of the space between the tranny and engine.. it's a piece of the shim in the hub, so it's not a structural piece, but it is a sign of things to come.. It's out of warranty, but it seems like southbend is good at accomodating.. I'm going to talk to them on Monday, and perhaps do a dual disc upgrade when I put the NV5600 in since I think I am getting pretty close to the 475 HP mark the clutch is rated at.
'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