Embedded C for Microcontrollers

Module aims

  • To introduce students who are proficient in MATLAB to C:  amongst the most widely-used ever amongst programming languages, and one which provides an excellent foundation for learning others (e.g. C++ and JavaScript).
  • To develop, from the basic knowledge of microcontrollers provided in ME2 Mechatronics, an ability to program, in C, mechatronic systems containing typical sensors and actuators.

ECTS units:    6   
Contributing to Course Elements: 6 to ME3-LCTVS or ME4-LCTVS

Learning outcomes

On successfully completing this module, students will be able to:

  • Recall the principal terminology of stored-program computer hardware and software
  • Write simple C programs manipulating text, numerical bit-pattern data
  • Design, make, test and document a functional mechatronic system containing an embedded microcontroller
  • Assemble a working microcontroller-based mechatronic system on a prototype board

Module syllabus

Introduction to C language: structure, types and variables, arrays, assignment operations, conditional expressions, flow control, switch.
Advanced C language: structures, functions, recursions, pointers.
Introduction to microcontrollers:  architecture, PIC18FXXX examples, the PICKit Programming Device, programming, debugging.
Bit operations: inputs and outputs: digital IO, analog IO.
Interrupts: 
Application: time-based interrupts.
Time measurement: oscillators, timers;  application to servo motors.
Further applications: recap of the material, LCD, ultrasonic distance measurement
Motor control:  stepper motors, DC motors, PWM, optical encoders.
Communication (master): Serial Protocol Interface, SPI-master, I2C.
Communication (slave): SPI-slave, RS232 to PC.

Pre-requisites

In order to gain the maximum benefit from ECM, students are expected to have a good understanding of ME1 and ME2 mechatronics as well as ME1 computing, including:

  • Use of oscilloscope
  • Assembling simple circuits (breadboard)
  • Standard programming structures: conditional statements (if…  then… else), loops (e.g. for… next)
  • Binary and hexadecimal number bases.
  • Resistor network analysis
  • Pulse width modulation
  • Sampling
  • Data acquisition

Teaching methods

  • Duration: Spring term (10 weeks)
  • One 3-hour lab-based tutorial per week, supported by in-situ lectures.
  • Non-assessed hands-on system construction and programming exercises supported by tutor feedback.
  • Individual system construction and programming project chosen from a closed list.

Summary of student timetabled hours:
Lectures: 10
Tutorials:  20
Total:  30
Expected private study time:  5hr per week on individual project.
 

Assessments

No examination.

Individual project:  200 marks.

Module leaders

Dr Ravi Vaidyanathan