NefMoto

Technical => Reverse Engineering => Topic started by: barex on November 05, 2022, 12:40:33 PM



Title: EDC15 Map switching another way to show selected map
Post by: barex on November 05, 2022, 12:40:33 PM
Hi
After weeks of trying i have finally working multimap in my daily car :D
Big thanks to nihalot who share his knowledge how to do it in this topic
http://nefariousmotorsports.com/forum/index.php?topic=12637.0


But I also have an old off-road car with a swaped 1.9tdi engine. I would like to use this modification there, but the dashboard is analog. So I thought to display the selected engine map using the glow plug control light(pin 40 in 012 ECU) One blink the first map, etc.

I figured out which pin of cpu control glow plug control light, its 51pin named  P2.4
when i add
Code:
bclr P2.4

to the code the light is on. But how to blink this light without messing up rest of the program?
Using "delay" it is a bad idea?
Maybe someone did something like this and would like to share information about where to start and what to look for?
I am completely new to the world of assembler and processors so any information will be valuable.


Title: Re: EDC15 Map switching another way to show selected map
Post by: terminator on November 05, 2022, 03:27:08 PM
I believe there should be a routine that controls the glow plug lamp and it will do everything. All you need is to find it and pass some values (I think one of them is a mode(blinking, lighting etc)).
Similiar way you can deactivate it.


Title: Re: EDC15 Map switching another way to show selected map
Post by: barex on November 05, 2022, 04:45:50 PM
You may be right, the glow plug indicator light starts flashing on some DTCs stored in memory. Just how to find this routine? I tried to look for the value of P2.4 in IDA pro but unfortunately I did not find it. Scrolling through the code, I noticed P2_4 values. Is P2.4 = P2_4? I guess it makes sense. Tomorrow I will search the code again. Maybe I can find something useful.
Or maybe there is a better way to find this?
Sorry for this noob questions but a few months ago I was afraid to open ecu so everything is new to me  ;D ;D


Title: Re: EDC15 Map switching another way to show selected map
Post by: terminator on November 05, 2022, 05:40:55 PM
I would search for a variable (not port).
something like:
bset var.1 or bclr var.1

P.S. I disassembled C166 a long time ago so I don't remember much.


Title: Re: EDC15 Map switching another way to show selected map
Post by: prj on November 06, 2022, 06:08:00 AM
The ECU runs an RTOS.
Almost every subroutine apart from the initialization runs in a task.
Tasks are scheduled to run in a certain raster. So fixed time (except some tasks that run crank-sync).

Add a counter, increment this counter every iteration, if MSB is set, turn it on, if MSB is not set turn it off.
Now you have blinking light.
If it's too slow/too fast, adjust.

For counter find free RAM.
Think about it like this:

uint8_t ctr = 0;
void 20ms_raster_task() {
   if (ctr > 0x80) {
      bclr P2.4
   }  else {
      bset P2.4
   }
   ctr++;
}

With this example the light is on for 2.56 seconds and after that off for 2.56 seconds, because 256 iterations of 20ms raster take 5.12 seconds to execute.


Title: Re: EDC15 Map switching another way to show selected map
Post by: fknbrkn on November 06, 2022, 02:06:49 PM
The ECU runs an RTOS.
Almost every subroutine apart from the initialization runs in a task.
Tasks are scheduled to run in a certain raster. So fixed time (except some tasks that run crank-sync).

Add a counter, increment this counter every iteration, if MSB is set, turn it on, if MSB is not set turn it off.
Now you have blinking light.
If it's too slow/too fast, adjust.

For counter find free RAM.
Think about it like this:

uint8_t ctr = 0;
void 20ms_raster_task() {
   if (ctr > 0x80) {
      bclr P2.4
   }  else {
      bset P2.4
   }
   ctr++;
}

With this example the light is on for 2.56 seconds and after that off for 2.56 seconds, because 256 iterations of 20ms raster take 5.12 seconds to execute.

Thats too slow and for adjusting delay ctr reset should be added instead of overflowing byte
You also want to zeros ctr when flashing done or the next time event starts at a random phase

Code:
uint_8t count // num of flashes
uint_8t delay // delay between flashes counter


if (count == 0xFF) {count = 0;} // iirc in me7 its 0xFF in non-used ram, so in code init should be done

if (count > 0) // from switching routine >> (if (new_map != old_map) { count = new_map; old_map=new_map;}  // new_map represents the value of current mapSet in range of 1-5 for example. fires once after map changed.

{
  if (delay < ??) { bset b_mil; }
  else {  bclr b_mil; }
  delay++;
 }
 if (delay > (??*2)) // 2.54 is a huge delay so zeros instead of overflowing  :-\
 {
  delay=0;
  count -=1; // eof blink
  }
}
else
{ delay = 0; } // reset timer after all blinks completed

OR

in me7 there is a B_milblk which blinks at 1hz freq and i suppose its a 1000ms / 20ms = 50 ticks on every phase and 100 ticks for complete cycle

so it could be simplified like that. notice about delay is a word now

Code:
uint16_t delay_w

if (delay_w >1) // from switching routine >> if (new_map != old_map) { delay_w = new_map * 100;  old_map=new_map;}
{
  bset B_milblk;
  delay_w -=1 ;
}
if ((delay_w == 1) or (delay_w == 0xFFFF))  // do not use 'else' to avoid conflict with a stock B_milblk routine when delay=0
{
 bclr B_milblk;
 delay_w = 0;
}


 


Title: Re: EDC15 Map switching another way to show selected map
Post by: prj on November 07, 2022, 01:22:27 AM
Thats too slow and for adjusting delay ctr reset should be added instead of overflowing byte
You also want to zeros ctr when flashing done or the next time event starts at a random phase
It was a bare minimum example for the concept, not finished code.
Because OP asked how to do delay, and clearly was not familiar with the RTOS.
Obviously if you want to adjust frequency and you want number of flashes you are going to have to implement something.

Did you just really try to "teach" me how to code?  ;D ;D ;D


Title: Re: EDC15 Map switching another way to show selected map
Post by: fknbrkn on November 07, 2022, 04:27:42 AM
It was a bare minimum example for the concept, not finished code.
Because OP asked how to do delay, and clearly was not familiar with the RTOS.
Obviously if you want to adjust frequency and you want number of flashes you are going to have to implement something.

Did you just really try to "teach" me how to code?  ;D ;D ;D

Thats obviously not for you )
But for op and those who came with the same questions, just more complex pseudocode


Title: Re: EDC15 Map switching another way to show selected map
Post by: barex on November 07, 2022, 03:47:37 PM
fukenbroken and prj you are geniuses :D
I was able to write an assembly language program according to your idea and it works :D
Unfortunately, I have one problem, when I use the bclr P2.4 function, the glow plug indicator does not light up at full power. It is slightly tinted.
Do you have any idea what it might be caused and how to improve it?

Even when I use the code written by nihalot in his tutorial and add bclr P2.4 to it, the glow plug indicator does not light up at full power. So I guess the code I wrote doesn't affect that.



Title: Re: EDC15 Map switching another way to show selected map
Post by: prj on November 08, 2022, 12:34:28 AM
Chances are that it's getting cleared immediately after in the normal code.
Find where the normal code is and make a condition, that when your logic is active, it should skip the clearing.

Or implement the OEM blinking, chances are if you use the OEM blinking solution then it will already skip clearing.