Download presentation
Presentation is loading. Please wait.
Published byNorma Charlotte Robbins Modified over 9 years ago
1
Arduino Microcontrollers SREEJAA SUNDARARAJU AND R. SCOTT CARSON BME 462
2
Parts of a sketch void setup() Runs at power-on and reset Used to initialize pins and variables void loop() Continually runs while the microcontroller is powered This is where work is performed
3
Arduino IDE Verify Upload New, Open, Save Serial Monitor
4
Defining a sample frequency Max ECG frequency ~150Hz F sample >= 2*150 Hz F sample = 5*150 Hz = 750 Hz We want to sample every 1.33 ms
5
Implementation 1 – delay() delay(int t) or delayMicroseconds(int t) Performs a busy wait for t time float ecg_reading = 0.0; int ecg = A0; void setup(){ Serial.begin(9600); } void loop(){ ecg_reading = analogRead(ecg); Serial.println(ecg_reading); delayMicroseconds(1333); }
6
Implementation 2 – Timer interrupt ATMega328 microprocessor has 3 timers Functionality defined by configuration registers Can be complex if you are unfamiliar with embedded programming http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA- 88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf TimerOne library - http://playground.arduino.cc/code/timer1 A wrapper class around Timer1 to provide easy access to Timer functionality, including configuring interrupts Interrupts – http://playground.arduino.cc/Code/Interrupts Interrupts are used to tell the CPU a certain event has occurred and to execute a specific function known as an Interrupt Service Routine (ISR) Interrupt events Counter reaching a specified value Button press Timer expiring This is the interesting one for us.
7
Timer Interrupts con’t #include void timerISR(); // Used to store analog value float ecg_reading = 0.0; int ecg = A0; // ECG analog pin volatile boolean timer_expired = false; void setup(){ Timer1.initialize(1333); Timer1.attachInterrupt(timerISR); Serial.begin(9600); } void loop(){ if(timer_expired){ noInterrupts(); ecg_reading = analogRead(ecg); Serial.println(ecg_reading); timer_expired = false; interrupts(); } void timerISR(){ timer_expired = true; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.