Difference between revisions of "EMG - PhantomX Reactor Robot"
Line 63: | Line 63: | ||
</pre> | </pre> | ||
+ | <h1> Analog-To-Digital Converter (ADC) </h1> | ||
+ | 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. |
Revision as of 19:38, 25 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.