Microcontroller FundamentalsLearning ObjectivesMechatronics Concept MapWhat is a Microcontroller?ATmega328 Internal ArchitectureATmega328 FeaturesArduino DuemilanoveArduino Uno R3Arduino DueArduino Duemilanove/Uno FeaturesPowerPoint PresentationATmega328 MicrocontrollerAbsolute MaximumsMicrocontroller Ports and PinsPort Pin Data DirectionalityATmega328 Block DiagramM68HC11 microcontrollerSetting the Pin Data DirectionPin VoltagesPin Used as an OutputPins as Inputs and Pull-up Resistors - 1Pins as Inputs and Pull-up Resistors - 2Pins as Inputs and Pull-up Resistors - 3Pins as Inputs and Pull-up Resistors - 4Spartronics Experimenter ShieldHandling the Arduino - How NOT to Do It!Handling the Arduino - The Proper WaySpartronics Experimenter LED PinoutSpartronics Experimenter Digital Pin AssignmentsSpartronics Experimenter Analog Pin AssignmentsBinary and Hexadecimal Numbers - 1Binary and Hexadecimal Numbers - 2Binary and Hexadecimal Numbers - 3Binary and Hexadecimal Numbers - 4Using Hex ValuesPracticeSolutionSo What?Data Direction RegisterATmega328 Registers of InterestPORT Pin and register detailsExample 1Example 2Structure of an Arduino ProgramDigital IO – Practice 1Digital IO – Practice 1 SolutionSlide 47Digital IO – Practice 2Digital IO – Practice 2 PseudocodeDigital IO – Practice 2 (Arduino style code)Slide 51Digital IO – Practice 3 (Port style code)Slide 53SummarySummary, cont.Microcontroller FundamentalsB. Furman18SEP2014Learning ObjectivesExplain the general architecture of a microcontrollerList the key features of the ATmega328 microcontrollerExplain the features and elements of the Arduino and Spartronics Experimenter Shield (SES)Explain the concepts of microcontroller pins as inputs and outputsConvert between binary and hexadecimal digitsMechatronics Concept MapController(Hardware & Software)System toControlSensorSignalConditioningPowerInterfaceActuatorUserInterfacePowerSourceBJ Furman 22JAN11ME 106ME 154ME 157ME 195ME 120ME 297AME 106ME 120ME 106ME 190ME 187ME 110ME 136ME 154ME 157ME 182ME 189ME 195ME 106ME 120ME 106 INTEGRATIONWhat is a Microcontroller?http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC05TB.pdfANALOGINPUTSWhat is the difference between a ‘Digital Input’ and an ‘Ana log Input’?ATmega328 Internal ArchitectureATmega328 data sheet pp. 2, 5http://www.adafruit.com/index.php?main_page=popup_image&pID=50ATmega328 FeaturesATmega328 data sheet p. 1http://www.atmel.com/Images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet.pdfArduino Duemilanove http://www.arduino.cc/en/Main/ArduinoBoardDuemilanovehttp://arduino.cc/en/uploads/Main/ArduinoDuemilanove.jpgPin 13 LEDUSBconnectorBarrel jackDigital pins headerReset buttonATmega328 MCUAnalog pins headerPower-ground headerSee the handout: Arduino_ATmega328_pin_mapping_and_schematicArduino Uno R3http://www.adafruit.com/index.php?main_page=popup_image&pID=50ATmega16u2 replaces FT232RL for USB-serial communicationSee: http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-uno-faqArduino DueAtmel SAM3X8E processor (32 bit ARM Cortex M3 architecture, 84MHz)http://www.adafruit.com/index.php?main_page=popup_image&pID=1076See: http://arduino.cc/en/Main/ArduinoBoardDueNote: 3.3 V !!Arduino Duemilanove/Uno FeaturesMicrocontroller ATmega168/328Operating Voltage 5VInput Voltage (recommended) 7-12VInput Voltage (limits) 6-20VDigital I/O Pins 14 (of which 6 provide PWM output)Analog Input Pins 6DC Current per I/O Pin 40 mADC Current for 3.3V Pin 50 mAFlash Memory16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB used by bootloaderSRAM 1 KB (ATmega168) or 2 KB (ATmega328)EEPROM 512 bytes (ATmega168) or 1 KB (ATmega328)Clock Speed 16 MHzhttp://www.arduino.cc/en/Main/ArduinoBoardDuemilanovehttp://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdfATmega328 MicrocontrollerPin numberPin nameSpecial functionSource:http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega328PNote the limitations!p. 316Absolute MaximumsATmega328 data sheet p. 316Microcontroller Ports and PinsThe communication channels through which information flows into or out of the microcontrollerEx. PORTBPins PB0 – PB7May not be contiguousOften bi-directionalCSee next slides!Port Pin Data DirectionalityInputWhen you want to take information from the external world (sensors) int o the MCUOutputWhen you want to change the state of something outside the MCU (turn a motor on or off, etc.)Pins default to input direction on power-up or resetYour program can set or change the directionality of a pin at any timeATmega328Block DiagramInputOutputM68HC11 microcontrollerSetting the Pin Data DirectionArduinopinMode(pin_no., dir)Ex. Make Arduino pin 3 (PD3) an outputpinMode(3, OUTPUT);pinMode(PIN_D3, OUTPUT); // with me106.hNote: one pin at a timeSuppose you wanted Arduino pins 3, 5, and 7 (PD3, PD5, and PD7) to be outputs?Is there a way to make them all outputs at the same time?Yes! Answer coming later…Pin VoltagesMicrocontrollers are fundamentally digital devices. For digital IO pins:Information is ‘coded’ in two discrete states:HIGH or LOW (logic: 1 or 0)VoltagesTTL5 V (for HIGH)0 V (for LOW)3.3 V CMOS3.3 V (for HIGH)0 V (for LOW)Pin Used as an OutputTurn on an LED, which is connected to pin Arduino pin 0 (PD0) (note the resistor!)What should the data direction be for pin 0 (PD0)?pinMode(____, ____);Turn on the LEDdigitalWrite(0,HIGH);Turn off the LEDdigitalWrite(0,LOW);ATmega328Arduinopin 0(PD0)Pins as Inputs and Pull-up Resistors - 1Using a switch as a sensorEx. Seat belt sensorDetect the switch stateWhat should the data direction be for Arduino pin 3 (PD3)?pinMode(____, ____);What will the voltage be on PD3 when the switch is closed?What will the voltage be on PD3 when the switch is open?Indeterminate!ATmega328Arduinopin 3(PD3)Pins as Inputs and Pull-up Resistors - 2Switch as a sensor, cont.Make the voltage on the pin determinate by turning on the pull-up resistor for PD3Assuming PD3 is an input:digitalWrite(3,HIGH); turns on the “pull-up” resistorpinMode(3,INPUT_PULLUP);What will the voltage on PD3 be when the switch is open?VTGWhat will the voltage on PD3 be when the switch is closed?ATmega328PD3VTG= +5V01Pins as Inputs and Pull-up Resistors - 3Switch as a sensor, cont.To turn off
View Full Document