What is an Output Device?
Output devices in electronic systems transfer energy from the electrical energy that has been processed to another kind of energy, often light, sound or movement (kinetic). Output devices can be digital or analogue.
Devices which perform an “Output” function are generally called Actuators.
Assignment:
Individual
- Add an output device to a microcontroller board you've designed, and program it to do something
Group
-Measure the power consumption of an output device
Software :
-Eagle
-Mods
-Arduino IDE
Materials :
-FR1
-Eelectronic Components
Accomplised
-Designed, Milled and Programmed a Modular board
-Understood the connections of the same
-Designed, Milled a LED array Shield
-Used Led array as an output device
-Used Stepper Motor as an output device
HeatBot
An immersive experience introducing a next-generation chatbot.Using Facebook Messenger as an interface, HeatBot asks visitors a few questions about how they’re feeling. Linked to a chatbot with eight core emotions and over 1,000 responses, HeatBot then engages visitors through a stream of personalized photos, GIFs and sounds, while simultaneously displaying a glowing, colorful emotional response on a 42” x 42” LED matrix panel. Users are sent away with a GIF and static image of themselves inside to share.
Having understood the basics of it I took it to Eagle and started designing. The fab kit uses atmega168, whereas satshakit uses Atmega 328p. My lab had the availability of 328p and is better than 168, so I decided to use 328.
Specification of Atmega 328P
The Atmel 8-bit AVR RISC-based microcontroller combines 32 kB ISP flash memory with read-while-write capabilities, 1 kB EEPROM, 2 kB SRAM, 23 general purpose I/O lines, 32 general purpose working registers, three flexible timer/counters with compare modes, internal and external interrupts, serial programmable USART, a byte-oriented 2-wire serial interface, SPI serial port, 6-channel 10-bit A/D converter (8-channels in TQFP and QFN/MLF packages), programmable watchdog timer with internal oscillator, and five software selectable power saving modes. The device operates between 1.8-5.5 volts. The device achieves throughput approaching 1 MIPS per MHz.
The Following are the components that I needed to design my board:
Components List
1x ATMega 328p
1x 10kΩ resistor
1x 499Ω resistor
1x 1kΩ resistor
1x 1uF Capacitor
2x 22pF Capacitor
1x Red LED
1x Blue LED
1x 16Mhz Crystal
1x Micro USB Conenctor
The following is the revised Component list.
Component List
1x ATMega 328p
1x 10kΩ resistor
1x 499Ω resistor
1x 1kΩ resistor
1x 0Ω resistors
1x 1uF Capacitor
1x 10uF Capacitor
1x 100nF Capacitor
2x 22pF Capacitor
1x Red LED
1x Blue LED
1x 16Mhz Crystal
1x Micro USB Conenctor
Components required to design LED array board
Component List
3x 499Ω resistor
9x 0Ω resistor
6x White LED
3x Yellow LED
Possible reasons for failure.
1.Wrong shield design
2.Possible connection error
3.Wrong program.
Since there is no exact reference to what I want, I need to study Charlieplexing properly and try redesigning the board.
Servo Motor
Anyhow to check an output device with my board I used a servo motor and ran it with a simple sweep code, that is available in the example programs of the Arduino software.
The servo motor is usually a simple DC motor controlled for specific angular rotation with the help of additional servomechanism (a typical closed-loop feedback control system). Now day’s servo system has large industrial applications.
Timer
So basically, a timer is a register! But not a normal one. The value of this register increases/decreases automatically. In AVR, timers are of two types: 8-bit and 16-bit timers. This means that the 8-bit timer is capable of counting 2^8=256 steps from 0 to 255 as demonstrated below.
Timer Concepts
Since childhood, we have been coming across the following formula:
Timer Register
You can change the Timer behavior through the timer register. The most important timer registers are:
TCCRx - Timer/Counter Control Register. The prescaler can be configured here.
OCRx - Output Compare Register
ICRx - Input Capture Register (only for 16bit timer)
TIMSKx - Timer/Counter Interrupt Mask Register. To enable/disable timer interrupts.
TIFRx - Timer/Counter Interrupt Flag Register. Indicates a pending timer interrupt.
Prescaler
The pre-scaler divides the system clock by a fixed amount, usually a binary fraction so that the timer itself can be incremented at a slower rate and thus cover a longer interval before it overflows and rolls over. The prescaler can be set to 8, 64, 256 or 1024 compared to the system clock.
The trade-off for covering a longer interval is that you can no longer resolve very short intervals.
Clock select and timer frequency
Different clock sources can be selected for each timer independently. To calculate the timer frequency (for example 2Hz using Timer1) you will need:
1. CPU frequency 16Mhz for Arduino
2. maximum timer counter value (256 for 8bit, 65536 for 16bit timer)
3. Divide CPU frequency through the chosen pre-scaler (16000000 / 256 = 62500)
4. Divide result through the desired frequency (62500 / 2Hz = 31250)
5. Verify the result against the maximum timer counter value (31250 < 65536 success) if fail, choose bigger pre-scaler.
Interrupts
Well, this is not exclusively related to timers, but I thought of discussing it as it is used in a variety of places. Let me explain it using an analogy. Say now you are reading my post. It's dinner time and your mom (only if you live with your mom ;)) calls you for dinner. What do you do (if she gets too creepy)? You save your work and attend to your mom's call, then return and resume reading. This is an example of an interrupt.
In most microcontrollers, there is something called interrupt. This interrupt can be fired whenever certain conditions are met. Now whenever an interrupt is fired, the AVR stops and saves its execution of the main routine, attends to the interrupt call (by executing a special routine, called the Interrupt Service Routine, ISR) and once it is done with it, returns to the main routine and continues executing it.
For example, in the condition of counter overflow, we can set up a bit to fire an interrupt whenever an overflow occurs. Now, during execution of the program, whenever an overflow occurs, an interrupt is fired and the CPU attends to the corresponding ISR. Now it’s up to us what do we want to do inside the ISR. We can toggle the value of a pin, or increment a counter, etc etc.
//
// hello.servo.44.c
//
// servo motor hello-world
//
// set lfuse to 0x5E for 20 MHz xtal
//
// Neil Gershenfeld
// 4/8/12
//
// (c) Massachusetts Institute of Technology 2012
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all
// liability.
//
#include <avr/io.h>
#include <util/delay.h>
#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define position_delay() _delay_ms(1000)
#define PWM_port PORTA
#define PWM_pin (1 << PA6)
#define PWM_direction DDRA
int main(void) {
//
// main
//
// set clock divider to /1
//
CLKPR = (1 << CLKPCE);
CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
//
// set up timer 1
//
TCCR1A = (1 << COM1A1) | (0 << COM1A0); // clear OC1A on compare match
TCCR1B = (0 << CS12) | (1 << CS11) | (0 << CS10) | (1 << WGM13); // prescaler /8, phase and frequency correct PWM, ICR1 TOP
ICR1 = 25000; // 20 ms frequency
//
// set PWM pin to output
//
clear(PWM_port, PWM_pin);
output(PWM_direction, PWM_pin);
//
// main loop
//
while (1) {
//
// 1 ms PWM on time
//
OCR1A = 1250;
position_delay();
//
// 1.5 ms PWM on time
//
OCR1A = 1875;
position_delay();
//
// 2 ms PWM on time
//
OCR1A = 2500;
position_delay();
}
}
The highlighted portions of the code talk about timer and clock setting. Note that this is for Attiny44 controller.
The CLKPR is the clock prescaler and in this case its 0,0,0,0 which means its at default and no prescaling is done.
TCCR1A & TCCR1B are different TIMER 1 registers.
OCR1A is again a register for TIMER1 that in this case controls the delay of the servo.
In Arduino programming, the servo uses a library called servo.h. All the timer configurations are taken care of by the library hence the coding becomes very simple. Since I use Arduino for my programming I Just have to call the library and used the functions therein.
The assignment was to measure the power consumption of an output device. As done earlier we decided to connect a DC motor to the oscilloscope. The motor was connected to the power jack. My contribution was to read about the connections and how to configure the oscilloscope to read the values from the motor.
Conclusion
The week's assignment was quite straightforward, but things got interesting and difficult because I wanted to make a modular board. As I said earlier, this is something that was far-fetched, before I started this course and it gave me a great sense of satisfaction to have actually designed and produced a modular board. This week, however, gave me a clearer picture of how I need to go about the electronics part of my project. There are still certain things in electronics that I am unable to understand or why they have to be done in a certain way. Probably in time, I will understand them.