element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Ben Heck Featured Content
  • Challenges & Projects
  • element14 presents
  • element14's The Ben Heck Show
  • Ben Heck Featured Content
  • More
  • Cancel
Ben Heck Featured Content
Forum Engine Management
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Ben Heck Featured Content to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 63 replies
  • Subscribers 46 subscribers
  • Views 4146 views
  • Users 0 members are here
Related

Engine Management

jack.chaney56
jack.chaney56 over 9 years ago

Hi Ben,

I am a programmer with a very small amount of skill with circuits, and am looking to create a platform for an engine management system, using an Arduino Mega 2560. I had done a bit of the coding, when I ran into some timing issues with the built in Arduino manager, so I switched over and started using AVR Studio and a programmer to go directly to the chip itself.  The code looks like it should work ok, but now I need some additional circuits to handle the energy levels of coils and injectors (Something like IGBTs). Sensors are being run through simple dividers (no protection yet), and cam and crank inputs are through a simple comparitor

 

Let me know what you think,

Jack

  • Sign in to reply
  • Cancel

Top Replies

  • jack.chaney56
    jack.chaney56 over 7 years ago +2
    Back again... After a bit of time away seeking enlightenment (and a steady paycheck), I am ready to get back to work on my project. I have continued to play around with the code and a number of components…
  • jack.chaney56
    jack.chaney56 over 7 years ago +2
    I want to start this thing right, so the shopping list for people that want to play along at home: Raspberry Pi - version is not significant if you don't mind a slow response when using Eclipse, but 3B…
  • jack.chaney56
    jack.chaney56 over 7 years ago +2
    Start off with two things. First, I forgot (neglected) to provide instruction on how to get the compiled code onto the Nano. Fault of familiarity; having done the process so many times, I had shifted to…
Parents
  • jack.chaney56
    jack.chaney56 over 7 years ago

    My favorite word errata.  I had the chance to compile the code, and found a few "undocumented features" (bugs) in what I posted. The good news is half the files are clean.

    A2D.c

    EEPROM.c

    LATCHES.c

    and UART.c

    The main issue with stuff was undeclared variables and constants, so start at the top.

    types.h

    line 71 should be DEG_PER_REV not DEGS_PER_REV

    line 73-75 should be declared as long so add an 'L' to the end of the numbers

    ...additions.  Because the variables are shared globally for now, need to add to the extern list

    extern UByte tkHi, tkLo;

    extern UByte cylCt;

    extern UWord tkEv[];

    extern UWord tkSt[];

     

    TIMERS.c

    Like I said, setTach needed to be defined, so make a call to access one of the latches.

    void setLatch(UByte, bool);

    void setTach(bool t) { setLatch(23, t); }

     

    IGNCRKCAM.c

    This one had a lot of things missing, mostly What I think of as loop closing stuff.

    add line #define FIVE_DEG  466

    add prototype SLong getTime1(void);

    line 34: correct spelling SLong camTime not SLong camTIme

    add some variables

         UByte cylCt;

         UWord tkEv[8];

         UWord tkSt[8];

    add a switch detection for cam detected

         UByte camDet = 0;

         bool isCamDet(void) { return (camDet != 0); }

         void setCamDet(bool t) { camDet = t ? 1 : 0; }

    line 50 remove toothAfterCam = 0; (just used for first example).

    declare variable in rtUpdateIgn routine

         UByte c;

    declare variables in INT(INT0_vect)

         UWord min, max;

     

    SCHEDULER.c

    missed some stuff due to not correcting the copy paste stuff

    add variables UByte tkHi, tkLo;

    in schedule(...) near line 73 the for loops were missing the closing bracket '}'

    also closing bracket for second for loop.

    The variable name in the second for loop should be cylCt (copy paset error)

     

    ...and for some reason when writing a C program it is necessary to have a main function, but I didn't really provide one.

    #include "types.h"
    void initIgn(void);
    void initA2D(void);
    void initLatches(void);
    void initTimers(void);
    void initUart(void);
    int main(void) {
     initA2D();
     initLatches();
     initTimers();
     initUart();
     initIgn();
     forever { }
     return 0;
    }

     

    Something will go in the forever loop, in a bit, or you can plug in your own ideas in the meantime.

     

    (sloppy) Jack

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • jack.chaney56
    jack.chaney56 over 7 years ago

    My favorite word errata.  I had the chance to compile the code, and found a few "undocumented features" (bugs) in what I posted. The good news is half the files are clean.

    A2D.c

    EEPROM.c

    LATCHES.c

    and UART.c

    The main issue with stuff was undeclared variables and constants, so start at the top.

    types.h

    line 71 should be DEG_PER_REV not DEGS_PER_REV

    line 73-75 should be declared as long so add an 'L' to the end of the numbers

    ...additions.  Because the variables are shared globally for now, need to add to the extern list

    extern UByte tkHi, tkLo;

    extern UByte cylCt;

    extern UWord tkEv[];

    extern UWord tkSt[];

     

    TIMERS.c

    Like I said, setTach needed to be defined, so make a call to access one of the latches.

    void setLatch(UByte, bool);

    void setTach(bool t) { setLatch(23, t); }

     

    IGNCRKCAM.c

    This one had a lot of things missing, mostly What I think of as loop closing stuff.

    add line #define FIVE_DEG  466

    add prototype SLong getTime1(void);

    line 34: correct spelling SLong camTime not SLong camTIme

    add some variables

         UByte cylCt;

         UWord tkEv[8];

         UWord tkSt[8];

    add a switch detection for cam detected

         UByte camDet = 0;

         bool isCamDet(void) { return (camDet != 0); }

         void setCamDet(bool t) { camDet = t ? 1 : 0; }

    line 50 remove toothAfterCam = 0; (just used for first example).

    declare variable in rtUpdateIgn routine

         UByte c;

    declare variables in INT(INT0_vect)

         UWord min, max;

     

    SCHEDULER.c

    missed some stuff due to not correcting the copy paste stuff

    add variables UByte tkHi, tkLo;

    in schedule(...) near line 73 the for loops were missing the closing bracket '}'

    also closing bracket for second for loop.

    The variable name in the second for loop should be cylCt (copy paset error)

     

    ...and for some reason when writing a C program it is necessary to have a main function, but I didn't really provide one.

    #include "types.h"
    void initIgn(void);
    void initA2D(void);
    void initLatches(void);
    void initTimers(void);
    void initUart(void);
    int main(void) {
     initA2D();
     initLatches();
     initTimers();
     initUart();
     initIgn();
     forever { }
     return 0;
    }

     

    Something will go in the forever loop, in a bit, or you can plug in your own ideas in the meantime.

     

    (sloppy) Jack

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • jack.chaney56
    jack.chaney56 over 7 years ago in reply to jack.chaney56

    Always one more thing... In the 1mS timer operation there needs to be calls to update the A/Ds and invoke the ignition, both are the rtUpdate routines

    rtUpdateA2D();

    rtUpdateIgn();

     

    Jack

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube