[ Log In ]

Introduction to the Atmel Atmega32 AVR microcontroller and the pin assignments (what each pin of the chip does). The pins include PORTs (PORTA, PORTB, PORTC and PORTD) and 8 pins for each port, ADC (Analog to Digital Converter), PWM (Pulse Width Modulation), and serial forms of communicatgion like I2C, SPI, UART, USART, and much more.

Making the simple circuit to connect an LED (Light Emitting Diode) with a resistor to an Atmel AVR Atmega32 microcontroller connected to PORTB Pin 0.

Description and physical view of the 8 pins of PORTB on the Atmel AVR Atmega32 microcontroller.

Code for Setting a pin for output (data direction for a port - DDR) using binary notation for the Atmel AVR microcontroller.

How to set a particular pin on the Atmel AVR microcontroller as high (logical 1 or high voltage - i.e. 5v, 3.3v, etc.) or low (logical 0 or zero voltage) using PORT register (i.e. PORTB).

Modifying the make file to make sure the C or AVR-GCC program can be compiled and trasfered into the AVR microcontroller under WINAVR and using the program called mfile. This consists of changing the programmer to USBTiny or the programmer of choice and changing the microcontroller and setting the correct port that the programmer is plugged into.

The results of the single LED circuit and program of turning on the LED using PORTB and Pin 0 after the program was transfered into the AVR microcontroller.

Connecting a push button switch to the microcontroller on a breadboard with a capacitor for hardware debouncing. The push button switch is connected to a general IO pin (in this case PORTB and Pin 1).

Programming for push button switch functionality on the Atmel AVR microcontroller on PORTB Pin 1 using the condition that uses the bit_is_clear(PIN?, ?) function. In this case, the push button has a capacitor to provide for hardware debouncing.

Schematic on paper of one button with hardware debouncing and two LEDs (Light Emitting Diodes) connected to an AVR microcontroller. The push button switch is connected to pin 1 on PORT B and the LEDs are connected to pin 0 and pin 2 on the same port. These are green LEDs so a 330ohm resistor is used to limit the current through the LED.

Breadboard circuit of one button with hardware debouncing and two LEDs (Light Emitting Diodes) connected to an AVR microcontroller. The push button switch is connected to pin 1 on PORT B and the LEDs are connected to pin 0 and pin 2 on the same port. These are green LEDs so a 330ohm resistor is used to limit the current through the LED.

Two LEDs and one push button is connected to an AVR microcontroller on PORTB. The LEDs are connected to pin 0 and pin 1. The push button is connected to pin 2.

An attempt is made to explain how the software debouncing works. A string of 0s and 1s are visually represented to show what may be going on when a button is pressed and a solution to overcome the portion of the 1s and 0s where there is uncertainty. A counter is used to increase a variable to represent the confidence level of the button press or release.

7 LEDs are connected to PORTB pins 0 to 6. The 7th pin has a push button. On PORTD 7 LED are connected to pins 0 to 6 and on the 7th pin a push button is connected to the AVR microcontroller.

7 LEDs are connected to PORTB on pins 0 to 6 and a push button is connected to pin 7 on that port. On PORTD, 7 LEDS are connected to pins 0 to 6 and one push button is connected to pin 7. Resistors are connected in series with the LEDs to limit the current so the LEDs don't burn out.

A Push Button and 7 LEDs are Initialized on PORTD and PORTB. The Push Button is located on the 8th pin (pin 7) on each port and the 7 LEDs are located on the remaining pins of each port.

All libraries (header files .h) that are created for c or c++ programs must have code in them to make sure they are not compiled more than once. The use of #ifndef #define and #endif is used for this. The #ifndef means if not defined. If a define is in the top portion of the library file to demarkate the file by a special name, then an ifndef can be used to make sure the code in that library is omitted if the define was alreay seen by the compiler.

Initializing two push button and two LEDs using binary notation. The push buttons will be connected to pins 0 and 1 and the LEDs are connected to pins 2 and 3.

Using the buttonPress library for the Atmel AVR microcontroller. The function is called ButtonPressed and it returns a char for testing if the push button is actually pressed. The parameters are the button number, port where the button is connected, pin of the port where the button is connected, and the confidence level threshold.

The Timer/Counter is used to count against a known clock frequency, the internal clock source for the AVR microcontroller. In the first part of the experiment, an LED, connected to PORTB and Pin 0 is toggled every time the TCNT1 exceeds 10000. That makes the LED toggle 100 times per second, which is too fast for the eye to discern the blink.

The TCCR1B Timer/Counter Control 16-bit Register B is used to turn on the CS10 (Clock Select) option of the control register to enable the timer for no prescaling.

The Timer/Counter is used to count against a known clock frequency, the internal clock source for the AVR microcontroller. In the first part of the experiment, an LED, connected to PORTB and Pin 0 is toggled every time TCNT1 is counted to 10000 * 100 using another loop. This makes the LED toggle every second

The TCCR1B Timer/Counter Control 16-bit Register B is used to turn on the CS10 (Clock Select) option of the control register to enable the timer for no prescaling.

The Timer/Counter is used to count against a known clock frequency, the internal clock source for the AVR microcontroller. In the first part of the experiment, a set of LEDs (14 in all) is connected to PORTB and PORTD and will produce a chasing effect every second and every 7th of a second using the TCNT1 timer/counter.

The interrupt can be used to create an event when the timer/counter TCNT1 or TCNT0 achieves a specific value. The OCR1A is used to hold this value.

The TCCR1B is set to a prescaler of 64 using the Clock Select bits (CS10, CS11 and CS 12) and another control bit called WGM12 (Waveform Generation Mode) CTC Mode (Clear Timer on Compare). This will cause the TCNT1 to go back to 0 when the OCR1A value is hit.

sei() is used to enable global interrupts along with the timer interrupts enable control TIMSK.

To test the output, an LED is connected to PORTB pin 0 and toggled on the interrupt.

When using all 8 data lines for the LCD, you will need a full port and three more pins on the mictocontroller. Careful consideration should be made when selecting this port.

In this case, the data lines are connected to all the pins of PORTB.

The data pins of the LCD is labeled D0, D1, D2, D3, D4, D5, D6 and D7, and these are connected to PORTB pin 0 to pin 7 respectively. (i.e. D0 to pin 0, D1 to pin 1 and so on). The remaining control pins RS, RW and enable are connected to three pins of PORTD.

The #define statement is a macro. The #define statement can be use to substitute a name for a number. It can also be used to change the name of another definition.

Example: #define MrLCDsCrib PORTB

This makes MrLCDsCrib defined as PORTB, so MrLCDsCrib can be used wherever PORTB is used.

The #define also makes it convenient to change values whenever the need arises. Say, for instance, MrLCDsCrib was plugged into PORTA instead. Then only one statement would need to be changed rather than having to go throughout the program changing all of the PORTBs to PORTAs.

The #define can also be used to name numbers:

I generally only use #define statement for things that may change.

Every time you need to reference pin 5, LCDEnable can be used for this purpose.

To send a command to the LCD, the data port connected to the LCD must have the data on that bus and the data will remain on that bus while the next commands are invoked:

- The control port of the LCD should a the R/W line low to write.
- The register select (RS) of the LCD needs to be set low for command mode.
- The enable needs to be set high and wait and then set low. During this time, the LCD gets the information from the port of the command and port of the data lines.

Now the command can be zeroed.

To send a character to the LCD, the data port connected to the LCD must have the data on that bus and the data will remain on that bus while the next commands are invoked:

- The control port of the LCD should a the R/W line low to write.
- The register select (RS) of the LCD needs to be set high for character mode.
- The enable needs to be set high and wait and then set low. During this time, the LCD gets the information from the port of the command and port of the data lines.

Now the character can be zeroed.

The data direction for the data port must be input since we will be getting information from the LCD. All of the PORTB lines will be set low for this to happen.

The enable must be set high and wait for a little while using the asm volatile ("nop"); command a couple of times.

The R/W line is set high to have the LCD in read mode so we can receive data from the LCD.

The RS line is set low to be in command mode.

Turn the enable on and off and grabbing the data until the data gives us the not busy signal of < 0x80

When all of the reading from the LCD is completed, the port is set back to output so the rest of the program can be in output mode for sending commands and sending characters.

The AC (Alternating Current) first goes through a transformer to step down the voltage from the mains power (110v or 220v). The sine wave after the transformer is now a much more narrow sine wave, only peaking at the voltages corresponding to the transformer.

Rectification - using 4 diodes, or a bridge rectifier (which is 4 rectifier diodes) the sine wave portion that is in the negative region can be flipped up (or folding up) to the positive region. At this point, the AC looks more like hills rather than a sine wave. This happens because the diodes only let the current flow in one direction. The diodes are positioned and oriented in a way that makes both negative and positive portions of the sine way happen only in the positive direction.

The waveform (bumps) now need to be smoothed to match more like a line (DC). Adding capacitors will charge up like a battery and release the energy slowly. This creates a smoothing effect for the bumpy waveform.

To get the current to a specific voltage level to be used in the circuit, a voltage regulator is used. If a high dropout voltage regulator is used, the voltage level before the voltage regulator must be higher than the regulated voltage plus the dropout amount.

Regulators are used after the power supply has been converted to DC from AC. The regulator requires capacitors to create a current that the regulator will accept. The lowest portion of voltage on the input waveform must be the consideration for the lowest voltage acceptable to the voltage regulator to get the output voltage needed for the circuit.

The 7805 voltage regulator requires a .1 uf (microfarad) capacitor helps transient response.

A voltage divider is a way to decrease a voltage to a proportion of the circuit voltage using two resistors or a potentiometer. The proportion of two resistors will create that proportion output of voltage between the resistors (or the wiper in the case of a potentiometer).

A voltage divider is just two resistors of a specified value to create a proportion for a voltage output that exists between the two resistors.

ADCor Analog to Digital Conversion is the way the microcontroller provides you with a digital number corresponding to the analog voltage you give the microcontroller.

The microcontroller has ADC pins that will accept a voltage between a reference voltage and 0 volts. A voltage from a device can be connected to this pin. When the pin reads the voltage, it will put a number corresponding to this voltage in a register.

The number the microcontroller gives you is in proportion to the amount of voltage. Say your reference voltage in your circuit is 5v and you put 2.5 volts to an ADC pin. The microcontroller would give you 128 in the ADC register if the 8-bit ADC is used, or would give you 512 if the 10-bit ADC is used. If the pin received the reference voltage of 5v, then the microcontroller would give you 255 for the 8-bit ADC and 1023 for the 10-bit ADC.

ADCVAlue = ReferenceVoltage / 10-bit Max Number or 8-Bit Max number

The 10-bit maximum is 1023 and 8-bit maximum is 255

The center lead (Vout) of the potentiometer is connected to the ADC pin 0. The potentiometer's outer leads are connected to ground (GND) and 5V (VCC). These connections create the voltage divider. Optionally you can used resistors rather than wires for the two outer lead connections to minimize the possibility of a short where the resistance goes very low across the center lead to one of the outer leads.

The ADC needs to be powered. The ADC has its own power pins for AVCC and GND. the AVCC is connected directly to VCC (the 5V rail) and the GND is simply connected to GND on the - rail. Across these two power pins should reside a 100nf (nanofarad) or .1uf (microfarad) capacitor just like on the main power pins.

Another important pin for ADC is the voltage reference pin. This pin will receive the top voltage in our range of voltages we need to consider in the ADC input. Say, for instance, you don't want the 5v to be your voltage reference, because your device only has a range of 0v to 3.3v that will be delivered to the ADC. The top voltage in this range, 3.3v, should be connected to the ADC voltage reference Vref pin. If you had 5v connected to this Vref pin, but the device only gave you 0v to 3.3v, then your precision will be reduced.

The Vref pin can be set in programming, which is the case in this video clip.

The ADC (Analog to Digital Converter) converts an analog voltage between a range of voltages and provides an 8 to 10 bit number in proportion to the voltage sensed by the ADC.

In this video, the ADC automatically notifies of it's conversion complete using an interrupt. A potentiometer is used as a voltage divider to provide variable voltages to the ADC pin.

This is a general explanation of how the ADC pins and receiving analog voltages differ from the standard way of using the PORT pins.

Setting either a left shift or right shift for the result will make it easier to grab the data for 8-bit or 10-bit. It is how the number will be placed within the register that will hold the data. The number will be placed in the register as left justified or right justified using terminology from word processors. This is important because the data will reside in two registers, because a 10-bit number will not fit in just one 8-bit register.

The bit that needs to be set is ADLAR if you want the data to be shifted to the left. This will put the 8-bit information in one register called the ADCH (ADC High) and make it very easy to get the number without having to do any bitwise manipulations.

The ADLAR is in the ADMUX register.

Since this Freescale accelerometer requires a different voltage than the AVR microcontroller, another voltage regulator is used (Maxim MAX604). The MAX604 will be positioned on the other extreme side of the breadboard. The MAX604 uses 2 10uf capacitors to smooth the power signal at the input and the output. One portion of the power rails is dedicated to the 3.3v so the accelerometer can easily be connected to power.

To convert more than one analog signal using the ADC, multiple channels must be used. In this case, an accelerometer will be connected to channel 0 and channel 1 of the ADC. The X axis is connected to channel 0 and the Y axis is connected to channel 1.

To smooth the analog signals, 10 uf (micro farad) capacitors will be used on each channel.

To power the accelerometer, the MAX604 voltage regulator with supporting capacitors are used.

A PWM can be converted to an analog voltage using capacitors. Since a PWM signal is a set of pulses, the capacitor will charge up with the pulses but release the charge slowly. The output voltage will match the voltage proportional to the pulses and the idle voltage.

If a specific waveform is desired, like an analog sine wave, PWM can be used to product an approximated sine wave using changes in the duty cycle of the PWM to match the amplitude of the voltages at the periods of the PWM. Capacitors can be used to smooth this approximation to try to match the sine wave.

Important aspects of outputting to more than one pin are as follows:

- Make sure the pins that will output the PWM are set for output data direction (i.e. DDRB = 0xFF for all PORT B pins output)

- Make sure that the pins will be set high in the interrupt service routine (ISR)

- Add another line within code block of the if (TCNT1>=800 && TCNT1<=2400) and make sure the pin reflect the correct output pin and the number after the TCNT1 >= value is correctly set for the position for that servo on that pin.

Important aspects of outputting to more than one pin are as follows:

- Make sure the pins that will output the PWM are set for output data direction (i.e. DDRB = 0xFF for all PORT B pins output)

- Make sure that the pins will be set high in the interrupt service routine (ISR)

- Add another line within code block of the if (TCNT1>=800 && TCNT1<=2400) and make sure the pin reflect the correct output pin and the number after the TCNT1 >= value is correctly set for the position for that servo on that pin.

Important aspects of outputting to more than one pin are as follows:

- Make sure the pins that will output the PWM are set for output data direction (i.e. DDRB = 0xFF for all PORT B pins output)

- Make sure that the pins will be set high in the interrupt service routine (ISR)

- Add another line within code block of the if (TCNT1>=800 && TCNT1<=2400) and make sure the pin reflect the correct output pin and the number after the TCNT1 >= value is correctly set for the position for that servo on that pin.

Only three servos were available, so the true output will not be shown.

Important aspects of outputting to more than one pin are as follows:

- Make sure the pins that will output the PWM are set for output data direction (i.e. DDRB = 0xFF for all PORT B pins output)

- Make sure that the pins will be set high in the interrupt service routine (ISR)

- Add another line within code block of the if (TCNT1>=800 && TCNT1<=2400) and make sure the pin reflect the correct output pin and the number after the TCNT1 >= value is correctly set for the position for that servo on that pin.

The oscilloscope is connected to the signal pin of the pressure sensor. A tube is connected to the port of the pressure sensor. The oscilloscope will monitor the analog voltage that the pressure sensor outputs. The source of pressure is my own suction.

To have the microcontroller read a pressure sensor, the sensor is connected to the ADC (Analog to Digital Converter). In this case, the sensor is connected to the pin 0 of the ADC (PORT A).

AVCC (ADC Power VCC) is connected to the + rail and the AGND (ADC Ground) is connected to the - rail on the breadboard. Noise entering AVCC and AGND is filtered by a 100nf (nano farad) capacitor. The leads of the capacitor connect to the AVCC and AGND.

The pressure sensor is made into a breakout so it can be plugged into the bread board. The number 4 pin of the pressure sensor is connected to the pin 0 of the ADC. The number 2 pin of the pressure sensor is connected to the VCC 5v (since this is a 5v device) and the pin number 3 is connected to GND.

An interface (breakout) was created to make the connection from the LCD to the microcontroller easier. The DIY interface contains a trimmer potentiometer to adjust the contrast of the LCD. The interface has ribbon cable soldered and connected to the data lines of the LCD. The power, RS, R/W and Enable share another cable assembly that go to another part of the microcontroller.

This reduces the amount of space that the LCD uses on the breadboard.

In this case, the LCD data lines are connected to the PORT B of the AVR microcontroller. The E (enable), RW (Read Write) and RS (Register Select) are all plugged into PORT D. The power is plugged into the power rail.

An LED is connected to PORD Pin 0 of an AVR microcontroller. In this case, the LED is used to represent a motor that will turn on and off according to an ADC value.

The LED is connected to pin 0 on PORTD which is controlled by values from the ADC. The LED is actually representing a vacuum pump, so when the pressure sensor that is connected to the ADC passes a high threshold that will turn off the motor (pin to low) and if the ADC passes a low threshold, the motor will turn on (pin high). This will keep a vacuum in the tank between these two thresholds.

The LED is connected to pin 0 on PORTD which is controlled by values from the ADC. The LED is actually representing a vacuum pump, so when the pressure sensor that is connected to the ADC passes a high threshold that will turn off the motor (pin to low) and if the ADC passes a low threshold, the motor will turn on (pin high). This will keep a vacuum in the tank between these two thresholds.

The Relay requires a few other components to provide enough power to trip the relay coil (transistor) and a diode across the relay coil to protect the transistor from any back EMF that could be caused by the relay coil.

The relay will be controlled by a pin on the microcontroller. Since the microcontroller will not allow a draw of current that the relay coil will need, a transistor will be needed to switch on a higher current supply. The higher current supply is just the 5v that is powering the circuit. On of the pins of the transistor is connected to the pin of the microcontroller. This pin will have a resistor between the pin and the transistor (base). When the pin is high, the transistor will allow current to pass through the other two pins (collector and emitter).

The relay coil is connected to this part of the transistor so when the pin is high, the relay coil will fire. Since the coil can create back EMF, the coil will have a signal diode across the coil to keep any current from hitting the transistor.

To determine the current in a portion of a circuit, Ohm's law can be applied.

In this case, the current is being determine to find an appropriate transistor. So, prior to adding the transistor, the current is found and the transistor with at least that current rating can be selected.

The push button switch is connected to the first pin of the microcontroller (PORTB Pin 0) and the other end of the button is connected to ground since the pin will be in a high state.

The LED is connected to the microcontroller on the second pin (PORTB Pin 1) in series with the 330 ohm resistor the limit the current through the LED

The LED is connected to the microcontroller on the first pin (PORTB Pin 0) in series with the 330 ohm resistor the limit the current through the LED

First the data direction register for port b (DDRB) and pin 0 must be set for output since the LED is be controlled.

The high or low state of that pin is already at a low state (by default) and that is how it need to be at the initialization.

To change the microcontroller name (MCU Name), open the makefile with programmers notepad and at the upper portion of the file, there will be a # MCU Name. Just underneath this comment, there will be MCU =. After the = resides the name of the microcontroller. Change the name to the microcontroller that you will be using.

Using your favorite Schematic CAD software (Eagle is used in this video), print the traces and pads on the glossy side of toner transfer paper. Make sure the scale is set to 1 (or 100%).

Don't touch the glossy side of the paper. If you do, the toner will not transfer in the touched area. Cut the printed portion out and cut a piece of copper clad to the same size as the printed design.

Clean the copper on the PCB with a regular dish washing scrubbing pad and some dish washing soap. The author of this video does not recommend using sandpaper.


dimensionality reductions is taking a dataset with a higher dimensional complexity and reducing the number of dimensions, if the data suggests doing so.

For example, if the data set is 2 dimensional and the data points starts to show an arrangement of a one dimensional manifold (arrangement that appears that the data could be on a single dimension), then a function may be created that would rearrange the data to represent a single (or reduction) of dimensions.

It is important that the data maintains its structure after the reduction has occurred.

Once you click on the add tool within the schematic editor, a full list of the libraries will be shown in a dialog box. If nothing appears, or if a library is missing, go to the main window and right click the main libraries and select use all, or go to the specific library you want to use and right click on that library and click use.

There is a very broad variety of parts in the library. You will need to drill down to the part you need. You can also use the search.

Once you pick on a part, it will sow the part on the screen and you will need to place the part somewhere on the screen. It will allow you to place this part to many places if you wish. Press escape to stop placing the part, or click on the move tool.

The library dialog box will appear again is the escape key was pressed. If you don't need another part, just click on cancel.

Some parts will allow you to move specific sub portions of the part.

to move many parts at once, you will need to use the group tool. You can draw a rectangle around the parts, or click a polygon around the parts to be more precise in the selecting. Then you need to right click and select move group. If move group is not an option, you will need to click on move, then escape and right click again and the move group will be available.

The construction script is executed when the class blueprint is constructed in the level editor, not in game play. When the class blueprint is moved in the level editor view port, the construction script will keep executing.

The event graph is executed only during game play.

In the events graph of the blueprint, create a reference to the mesh in the blueprint that will be moved by right clicking in the events graph and selecting the mesh component, or by ctrl dragging the mesh from the My Blueprint panel onto the surface of the events graph.

The key to moving the mesh is to use add actor local offset. You can get this node by dragging from the mesh reference pin and typing in local offset.

The transform portion of the taks can be created from an outside call of some value as in this example by using a make vector node and passing in the event variable, or by simply changing the location transform X Y or Z values.

*another explanation in the description*
Watch with sound!
in this video i'll explain the interrupt coding principle.
the interrupt example is written to PIC16F887 but the explanation is relavent to a large variety of microcontrollers, including arduino!

feel free to comment with questions and requests.


if the principle is still not clear, reffer to this analogy:
imagine a situation where your phone can't ring or vibrate, during every day routine, in order to know if you got a call you need to constantly look at the phone's screen, So if you are waiting on an important phone call you will check the phone every few seconds, this is like the polling principle:

if(Pone_Ring())
Answer;
Rest_of_Life();
if(Pone_Ring())
Answer;
Rest_of_Life();
if(Pone_Ring())
Answer;
Rest_of_Life();

and so on.
but if your phone is fine, then you can do everything (within the legal boundaries) you want, and at the second you get a phone call a Flag will raise(you will hear the phone Ring) and you would answer it. without the need of constantly checking wheter you have a call or not.



music: Paintball theme, by Bird Creek

*another explanation in the description*
Watch with sound!
in this video i'll explain the interrupt coding principle.
the interrupt example is written to PIC16F887 but the explanation is relavent to a large variety of microcontrollers, including arduino!

feel free to comment with questions and requests.


if the principle is still not clear, reffer to this analogy:
imagine a situation where your phone can't ring or vibrate, during every day routine, in order to know if you got a call you need to constantly look at the phone's screen, So if you are waiting on an important phone call you will check the phone every few seconds, this is like the polling principle:

if(Pone_Ring())
Answer;
Rest_of_Life();
if(Pone_Ring())
Answer;
Rest_of_Life();
if(Pone_Ring())
Answer;
Rest_of_Life();

and so on.
but if your phone is fine, then you can do everything (within the legal boundaries) you want, and at the second you get a phone call a Flag will raise(you will hear the phone Ring) and you would answer it. without the need of constantly checking wheter you have a call or not.



music: Paintball theme, by Bird Creek