Difference between revisions of "EMG - PhantomX Reactor Robot"
Line 85: | Line 85: | ||
</pre> | </pre> | ||
− | where <i>pin</i> corresponds to the pin where we are reading the signal (e.g. | + | where <i>pin</i> corresponds to the pin where we are reading the signal (e.g. 0, 1,...,5) and value is the return value between 0 and 1023. |
<h1> EMG </h1> | <h1> EMG </h1> |
Revision as of 12:01, 26 February 2025
Contents
Timer
Note: Most of the information of this section is obtained from: https://www.prometec.net/timers/ Please refer to the previuos link and the library if you need more information.
A timer in electronics is a device or circuit used to measure and control time intervals. It generates precise delays or oscillations, making it essential in various applications like blinking LEDs, controlling motors or executing periodic events, between others.
It operates independently from the main program, allowing the microcontroller to perform other tasks simultaneously. Timers typically work by counting clock pulses from the microcontroller’s internal clock or an external source. They can be configured in various modes, such as delay generation, pulse width modulation (PWM), event counting, or frequency measurement.
Timers are configured by setting up several registers, to adjust the sampling time, durating, mode, starting, stoping,.... However, in our case, for the PhantomX React Robot, based on a AVR microcontroller, we will work with the TimerOne library.
TimerOne library
Important: If you do not have a libraries folder inside your <ARDUINO_MAIN_DIRECTORY>, create it and move the content inside it.
Main Functions of TimerOne library
This Section provides important information for the Timer handling. It is based on the explanation of different methods, but it does not explain the complete set of methods. To get and exahustive description of all methods the TimerOne.h must be studied.
Main methods are as follows:
- void initialize(unsigned long period) : Initializes and set the timer to period in microseconds.
- void setPeriod(unsigned long period) : Set the times to period in microseconds.
- void attachInterrupt(void (*isr)()) : Attachs a function to the timer that is called every period .
- void start(void): Starts the timer.
- void stop(void): Stops the timer.
For example, if you want to create a code that operates every second and blinks a led you need to
#include <TimerOne.h> const int led = 13; // the pin with a LED int ledState = LOW; // El LED empieza apagado void setup(void) { pinMode(led, OUTPUT); Timer1.initialize(1000000); // 1 second period Timer1.attachInterrupt(ISR_Blink); // Activates the interrupt and links it to ISR_Blink Serial.begin(9600); } void loop(void) { } void ISR_Blink() { ledState = !ledState; }
Analog-To-Digital Converter (ADC)
An Analog-to-Digital Converter (ADC) is a device or circuit used to convert analog signals into digital values that the microcontroller can process. It enables the measurement of continuous signals, such as temperature, light intensity, or voltage, allowing for interaction with the analog world.
The ADC operates by sampling the analog input at specific intervals and converting the measured voltage into a corresponding digital number. This conversion is typically controlled by the microcontroller’s internal clock, though external sources can be used for precise timing.
ADCs can be configured in various modes, such as single-ended or differential inputs, continuous or single conversion, and can support features like oversampling or interrupt-driven conversions. By working independently from the main program, the ADC allows the microcontroller to perform other tasks simultaneously while capturing analog data.
ADC arduino
When working with the Arduino ADC (Analog-to-Digital Converter), it is important to consider that we can only apply voltages up to a maximum of 5V (or 3.3V in specific boards). Otherwise, we risk damaging the board.
Moreover, and Arduino UNO or the Arbotix Board have a 10bits ADC resolution. This means that the 0 to 5V resolution are converted to 0-1023 value. Therefore a 5V equals 1023 while 2.5V corresponds to to 512.
In most of the boards, inputs A0 to A5 can be used as analog inputs, and the function to read it is:
int value = analogRead(pin);
where pin corresponds to the pin where we are reading the signal (e.g. 0, 1,...,5) and value is the return value between 0 and 1023.
EMG
For the course, we have created a module based on the XX amplifier.
It has 5 pins being:
- +Vs positive power - GND ground power - -Vs negative power - SIG signal - GND reference to the signal
It has been tunned in order to need only 3 signas to connect to the arduino:
- 5V -- To the 5V output of the arduino - GND -- To the GND of the arduino - SIG -- To the analog signal