1 / 13

Embedded Programming

Embedded Programming. B. Furman 09MAY2011. Learning Objectives. Distinguish between procedural programming and embedded programming Explain the Events and Services embedded programming framework Explain what an Event is Explain what a Service is Explain the key rule and its two corollaries

macy
Download Presentation

Embedded Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedded Programming B. Furman 09MAY2011

  2. Learning Objectives • Distinguish between procedural programming and embedded programming • Explain the Events and Services embedded programming framework • Explain what an Event is • Explain what a Service is • Explain the key rule and its two corollaries • Describe how an event checking routine works for • Discrete quantities • Analog quantities • Develop code for: • an event checking routine • a service • an event driven system

  3. PowerSource SignalConditioning PowerInterface UserInterface Actuator Sensor System toControl ME 110 ME 136 ME 154 ME 157 ME 182 ME 189 ME 195 Mechatronics Concept Map ME 106 ME 120 Controller(Hardware & Software) ME 106 ME 190 ME 187 ME 106 INTEGRATION ME 106 ME 120 ME 106 ME 154 ME 157 ME 195 ME 120 ME 297A BJ Furman 22JAN11

  4. Procedural vs. Embedded Programming • Procedural • ME 30/CmpE 46 • Computation and analysis programs • Mostly sequential • Start  …  End • Known inputs and outputs • Program is in control • Predictable operation and timing • Embedded • ME 106 • Inputs and outputs can occur at any time, in any order and are not predictable • Inputs can come from multiple sources • Sensors, user inputs, or internal (timer, ADC, etc.) • May handle simultaneous inputs and outputs • Program never ends

  5. Event Driven Program Structure • Programming task divides into: • Checking for events • Servicing events when they occur • Event • A detectable change or transition in something of interest • Button press (before: not pressed, after: pressed) • ADC complete flag bit set • Service • An action taken in response to an event

  6. Requirements for Events and Services • The occurrence of events must be checked for continuously and often • Services must execute quickly and must be non-blocking • Ex. Determine if a switch has closed • Blocking code: • while(digitalRead(pin) == HIGH);

  7. Event Checkers for Discrete Events • Ex. Check that a switch has closed • Pseudocode • IF switch is closed AND switch was open last time, THEN • SwitchClosed event has occurred • ELSE • SwitchClosed event has not occurred • Need to keep track of the state of the switch (i.e., maintain its history) • Use a state variable • Will need to be declared as a staticlocal variable in the function that checks for the event • Need to retain the value between successive calls to the event checking function

  8. Code to Check for Discrete Events

  9. Events involving an analog quantity A single-valued threshold will likely result in “chatter” when the quantify of interest is near the threshold http://www.soe.ucsc.edu/classes/cmpe118/Winter08/LectureNotes/EventDrivenProg.pdf

  10. Event Checkers for Events Involving Analog Quantities • Filtering the signal may help • Add hysteresis in the event checker • Make the criteria for when the event occurs a variable instead of a fixed value • Initially threshold is set to an upper value • As soon as the signal crosses the threshold, the threshold is dropped to a lower value • Pseudocode: • Set threshold to high value • IF var is greater than or equal to the threshold, THEN • Event has happened • Set threshold to lower value • ELSE • Event has not happened

  11. Event Detection with Hysteresis http://www.soe.ucsc.edu/classes/cmpe118/Winter08/LectureNotes/EventDrivenProg.pdf

  12. Code to Check for Events With Analog Quantities

  13. Main body of Events & Services Code

More Related