Thread: need help with some calculations

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    4

    need help with some calculations

    hello guys im working on a small bike ecu project

    what im trying to do at the moment is trigger the ignition coil on at a desired angle based on some sensor parameters

    now the thing that i got stuck for some days is to decode the engine crankshaft wheel correctly.

    lets take this example
    need help with some calculations-autotriggerfig1-gif

    my bike use a similar wheel its called 12-1 wheel becouse there is one teeth missing out of 12 so in reality there are 11 teeths . bike also use a sensor to count the teeths so it can adjust the mixture and ignition with some calculations.The sensor report 1 if a tooth is on the sensor or 0 if its not so we got something like this pulse
    need help with some calculations-jb5fs77-jpg
    now as we now eatch tooth is 30 deg since 360/12 = 30

    and lets say i want to trigger the ignition 45 deg before TDC(when the piston is on top) or 360 - 45 = 315deg.Now to trigger the ignition coil you need to wait 4.3ms(4300uS) to charge the coil before it fires the spark.
    Lets take some numbers to work with. I know for example that for one wheel rotation aka 360degs i need 12345uS that means if we do
    60000000 / 12345 = 4860 thats our rpm. Now if 12345uS its for 360
    then ( ( 360 - 45 ) / 360 ) * ( 12345 - 4300 ) =6501uS is the time to wait before triggering the ignition coil so the spark will be at 315degs as we want it.I need first to find a way to improve it if its possible and second i want to add a "trigger" offset. Trigger offset is for example when the tooth 9 is on sensor and piston is at TDC that means the piston is on top at 270 deg of the wheel

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    What happened at the 4th sample cycle?

    The first three measured 156, 147, 165 pixels (or 18, 17, 19 divisions respectively).
    But the 4th measured 226 pixels (27 divisions).

    There's no timebase on your picture (and if you're going to save pictures, please use PNG for all machine generated graphics, not JPG).
    But 18 divisions for a 12 pulse cycle gives an average of 1.5 divisions per pulse at 4800 RPM.

    What happened at the ?
    In just 1/4 of a revolution, the speed slowed to just 2400 RPM (a 3 division gap between pulses) and then sped back up again to something close to 4800 RPM.need help with some calculations-jb5fs77-png
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2019
    Posts
    4
    That pulse was captured when I kicked the bike so its fast at the beginning then it slows down since the engine its not working.Rpm while kicking is arroud 700-1000

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I'd say that a good place to start is to make some code that can pick when the 0deg point is.

    It would also need to be able to recover from a faulty reading.


    What are you using to read the value of the sensor? Is it an anologue port of a microcontroller? (Watch out for the ignition spark creating noise in the circuitry - Seporating ground, shielding, ect...)


    The first place that I'd start is measuring the time between the fall from 1000 (mV?) - From there you can start trying to find the larger gap.

    Also, have a look around for what other people have done
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Mar 2019
    Posts
    4
    well for now im using arduino mega

    and im using interrupts to capture the trigger from sensor when it sees a tooth

    Code:
    void TriggerIsr() { //this is the function that gets called by the interrupt
        TriggerTime = micros(); //returns the number of microseconds
    
    
        PreviusTriggerDuration = TriggerDuration;
        TriggerDuration = TriggerTime - PreviusTriggerTime;
    
    
        if (( PreviusTriggerDuration >  (3 * TriggerDuration) >> 1)  ) {
    //missing tooth detected
    
    
            if (teethCounter < 11 && (synced == true) ) {
    
    
                synced = false;
    
    
            }else {
    
    
                oneRevolution = !oneRevolution; //this is to detect the strokes
                teethCounter = 1;
                synced = true; //this is to check if we are sycned with the wheel or not
                TimeOn360 = PreviusTriggerDuration * 6; //this is the time for a 360 turn
    
            }
    
    
        }else {
    
            /*
    
            */
    
    
        }
    
    
        teethCounter++;
        oneTeethPreviusLastTime = PreviusTriggerTime;
        PreviusTriggerTime = TriggerTime;
    }
    then i will use a timer to delay for a specific time to trigger the ignition but this is the hard part let me explain more

    to charge the coil you need 4000 uS so for example at 12.000 rpm

    the delay of 4000 microseconds is at 288 degres based on this calculation:

    4000 * 360 / (60000000 / 12000) = 288 degs

    now if i want to trigger 45 degs before TDC i have to do

    360 - 45 = 315degs

    if my wheel is 12-1 and lets say the tooth 4 is when the piston is at TDC that means (4 - 1) * 30 = 90degs 360 - 90 = 270degs

    270 degs is the offset i need to add to the crankshaft angle calculation

    now to get the crankshaft angle im doing the following

    crankAngle = (teethCounter - 1) * 30 //this will give 30 deg acuracy
    crankAngle += 270 //crankshaft offset for TDC

    elapsedTime = (micros() - PreviusTriggerTime)
    crankAngle += (elapsedTime * 360) / PreviusTriggerTime

    if i didnt had the dwell time delay to charge the coil it could be simple be like this
    example : crankAngle = 185
    rpm = 12000
    ignition trigger deg before tdc = 315

    315 - crankAngle = 130 degs so (130 / 360) * (60000000 / rpm) =
    1805uS

    so i just had to delay for 1805 microseconds before triggering the coil.

    So my big problem is how to calculate the time for both dwell time (4000 uS) and ignition advance angle(360 - 45 = 315) time so i can set my timer and wait to trigger the spark

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Maybe you can use a Schmitt Trigger, using transistors as signal conditioning, transforming your signal in "square" wave. This will filter noise and give you a "stable" signal to work with.
    Why transistors? Because the level of the signal is not sufficient to use 'logical ports' (TTL 'high' is 2.8 V and CMOS circuits is, more or less, 2 V, minimum).

  7. #7
    Registered User
    Join Date
    Mar 2019
    Posts
    4
    hey i dont have problem with the signal im just having a problem with a calculation check the above post

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    45deg is going to be tricky because it doesn't line up with key - The best thing that you can do is an approximation.

    The reason is that you can't be sure that the engine is still in steady state.

    Have you considered more of a camshaft approach?
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ calculations
    By Learner87 in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2008, 08:51 AM
  2. Calculations
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 10:01 AM
  3. pi calculations
    By nbice in forum C++ Programming
    Replies: 7
    Last Post: 09-30-2002, 01:48 PM
  4. calculations
    By wayko in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 10:44 AM

Tags for this Thread