[ Log In ]

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.

A test of the actual circuit with the Atmel AVR microcontroller programmed showing the push button with debouncing using a capacitor across the two leads of the push button switch. Two LEDs (Light Emitting Diodes) are toggled when the push button is pressed and released. Results show that without debouncing the LEDs sometimes toggle twice or three times with one button pressed and release.

Showing the bouncing (mechanical bounce) effect with an oscilloscope for a push button switch with hardware debouncing introduced using a capacitor showing the effect of the voltage level when the push button is pressed.

The rationalle of using one method over the other and the tradeoffs. In software debouncing, the trade off is the microcontroller requires a few more cycles which can slow the execution of the program slightly and the variables needed for software debouncing requires a bit of memory. The trade-off with hardware debouncing is that the extra hardware (capacitor or capacitor/resistor pair) will introduce a cost to the circuit where if the circuit will be used in a product that will have thousands, or many thousands of units made, a hardware solution may be too expensive.

The power pins of the AVR may experience interference from time to time. It is advised to add a decoupling capacitor across the VCC and GND pins of the AVR microcontroller. If the capacitor is located far from these two pins, a high current loop could be formed. The recommended capacitor value is 100nf or .1uf.

A voltage regulator takes a higher voltage and provides a set voltage that the regulator is designed to output. There are a few types of regulators: switching regulators, high dropout regulators and low dropout regulators. Regulators have an input and an output. The input is the raw voltage that you provide through battery, wall adapter, power supply, transformer (with rectification and smoothing with capacitors). The output is the voltage that the regulator is designed to provide.

Dropout is the amount of voltage the regulator needs to keep the rated output voltage.

Examples of common voltage regulators:
7805 - provides 5 volts and is a high dropout
Max603 - 5v output
Max604 - 3.3v output

The 7805 Voltage regulator outputs 5 volts and requires at least 8 volts at the input (high dropout voltage). The middle pin is connected to ground.

Capacitors are needed to reduce the peak to peak (pk-pk) voltage difference which is considered noise from the power supply. The capacitors can also reduce interference from outside sources and from devices in the circuit.

A 10uF (microFarad) capacitor is used at the input side.
A .1uf capacitor is used at the output side.

The 7805 voltage regulator is connected to a breadboard to provide 5 volts to the circuit. Two capacitors are connected to the voltage regulator, 10uf (microfarad) on the input and .1uf on the output to reduce the peak to peak voltage difference.

Two sets of batteries are tested with this voltage regulator and the voltage dropout is determined by subtracting the input voltage to the output voltage.

The minimum recommended input voltage is 8 volts and the determined dropout is 1.5 volts. The 8 volts gives a .5 volt margin.

The MAX603 is a Voltage Regulator that will provide 5v output and can accept a voltage very close to this output voltage featuring its low dropout.

The input voltage is connected to pin 1 and the output of 5v is from pin 8. the two middle pins on each side is connected to ground. Pin 4 is the off pin and to have the regulator enabled, this pin must be connected to the input voltage or pin.

The set pin at pin 5 is a pin that if it is connected to gnd, that pin will tell the chip to use the set voltage output of 5v. If a resistor is connected to this pin, the output voltage can be modified.

A capacitor is connected between the output pin and gnd and another capacitor is connected to input and gnd. Both capacitor values are 10uF (microfarad)

The USB from the computer can be used to power the microcontroller circuit. The USB power is already a regulated power source, but another regulator can be connected with this input power. It is also recommended to use a 10uf (microfarad) capacitor at this input point (between the gnd and input voltage)

To get DC (Direct Current) from AC (Alternating Current), the AC which is a sine wave must be rectified, then smoothed. Rectification is required because half of the sine wave happens in the negative voltage region. Rectification is taking the negative part of the voltage and flipping it up to the positive region. Smoothing is where capacitors are used to store the rectified voltage (which looks like a bunch of humps) and makes it more like a line that has very small bumps. The higher capacitance, the smaller the bumps will be.

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.

A capacitor is used to smooth the rectified waveform. The capacitor charges as the voltage rises and holds that charge and the next pass of the current raises the charge of the capacitor and this keeps going, wave after wave. The current now has more of a direct current than before. More capacitors can cause this current to have less deflection and waviness.

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.

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 accelerometer is powered by batteries and regulated by the Maxim MAX604 chip with the discrete component of 10uf electrolytic capacitors.

The MAX604 outputs 3.3v which this accelerometer accepts as a valid power level.

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.

Capacitors can be used to smooth a rough or noisy signal. In this case, an accelerometer is being read by the ADC. The ADC is seeing a very noisy signal from the accelerometer.
A 10 uf (micro farad) capacitor is used to smooth the signal coming into the ADC. The result is a smoother signal and the response is acceptable, no apparent lag.

A 100 uf capacitor is also tested to determine if the signal can be smoothed even more. The result from the 100 uf capacitor is a bit smoother, but not enough to justify the use of a larger capacitor. The lag is greater with this capacitor and would probably be unacceptable.

Much of the noise may be coming from the breadboard itself, or the internal clock and other functions of the microcontroller.

When doing conversions with the ADC (Analog to Digital Conversion), the result may have a variance from conversion to conversion. This gives you a method to calculate this deflection over time and some possible techniques to minimize this deflection, such as using capacitors or using the ADC sleep mode.

When doing conversions with the ADC (Analog to Digital Conversion), the result may have a variance from conversion to conversion. This gives you a method to calculate this deflection over time and some possible techniques to minimize this deflection, such as using capacitors or using the ADC sleep mode.

To be able to measure the previous result to the current result, the previous result must be stored. Once the current result is captured, another variable is incremented by the absolute value of the difference of the result and the previous result.

First a few global variables are needed to store the previous result, total deflection over time, and the sample count (they start static volatile because the compiler would optimize them out if these keywords were not there):

When doing conversions with the ADC (Analog to Digital Conversion), the result may have a variance from conversion to conversion. This gives you a method to calculate this deflection over time and some possible techniques to minimize this deflection, such as using capacitors or using the ADC sleep mode.
Using the LCD, the ADC values are shown for testing the ADC conversion and collecting the deflection over many samples.

To be able to measure the previous result to the current result, the previous result must be stored. Once the current result is captured, another variable is incremented by the absolute value of the difference of the result and the previous result.

First a few global variables are needed to store the previous result, total deflection over time, and the sample count (they start static volatile because the compiler would optimize them out if these keywords were not there):

The ACD result and deflection is tested with a capacitors: 10 uf (micro farad) and 100 uf.

The ADC has a noise cancelling features described below:

Circuit Specific: Analog Noise Cancelling Techniques: The ground plane specifications, using an inductor or 10 mH and 100 nf (nano farad) .1 uf (micro farad) capacitor.

Programming: ADC Noise Canceler - ADC noise reduction and idle mode. Entering the ADC noise reduction mode will cause the CPU to stop when the ADC is starting a conversion. This will only work in ADC single conversion mode.

the ADC noise reduction mode is invoked by setting the SM0 bit in the MCUCR register, make sure the SM1 and SM2 is not set. The SE (Sleep Enable) bit must also be enabled in the same register.

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.

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.

The reference voltage is the top voltage that will be considered in the conversion. The pressure sensor output will be between 0v and 5v. Our circuit already has this voltage handy and it exists at the AVCC pin, so that is used as the reference.

The REFS0 bit is set to enable the AVCC to be used as the reference voltage. This bit is located in the ADMUX register.

In the datasheet, if this option is used, a capacitor is required between the AREF pin to GND.

The VCC pin is connected to the + power rail on the breadboard and the GND pin is connected to the - power rail. A .1uf capacitor should be connected across these two pins to filter noise.

At the feedback from the output to the inverting input resides a .01 uF capacitor. The inverting input will have a square wave that is rise above and fall below 5 volts where 5 volts is at the midpoint of the square wave.

When the square wave is abov ethe 5 volts, there will be current from the 5 volts, but not into the inverting input. The current goes to the capacitor. There will be a linear voltage change at the capacitor when current is applied to the capacitor. The voltage ramps down.

When the voltage is below the 5 volts, the current will be going in the other direction and the voltage will ramp up.

The end result is creating a triangle wave from a square wave.

The Name tool will allow you to name the part, or name the net, or other feature that may be on the schematic. The behavior of the name tool will vary with the thing you are naming. If you name a net for instance, and another net has the same name, the two next will be considered as a connection between the two nets.

The value tool will allow you to specify a particular value for the part. This can be any value that you feel will help you in identifying the part for use in the project. For example, if a capacitor is on the schematic, it might need a value like 22 pF to specify the capacitance.