[ Log In ]

Description of the never ending loop for AVR-GCC C or C++ programs to keep the microcontroller on and running using a while statement (while(1){}). One (1) is always gonig to be true, so the loop never ends.

The for loop explained and an example given.

While the loop iterates, i will be incremented by one on each iteration.

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.

A loop is needed to traverse the characters in the memory locations starting at the pointer.

To loop through a set of characters using a pointer:

To loop through a set of characters using a pointer:

A moving 'x' is displayed along all possible LCD cursor locations and the actual location of the 'x' is displayed on the bottom right of the LCD to inform what are the possible locations on the current LCD. Many LCDs have different row ans column specifications. This program allow the user to determine the constraints of their LCD so the LCD can be used within these cursor location constraints.

A for loop is used to cycle the 'x' in all of the cursor locations. An x is placed on the current location, a delay is used to give the user time to see the x and the location number. The cursor goes back to that location and displays a space to remove the 'x' so the next 'x' can be displayed and it appears to be moving.

A moving 'x' is displayed along all possible LCD cursor locations and the actual location of the 'x' is displayed on the bottom right of the LCD to inform what are the possible locations on the current LCD. Many LCDs have different row ans column specifications. This program allow the user to determine the constraints of their LCD so the LCD can be used within these cursor location constraints.

A for loop is used to cycle the 'x' in all of the cursor locations. An x is placed on the current location, a delay is used to give the user time to see the x and the location number. The cursor goes back to that location and displays a space to remove the 'x' so the next 'x' can be displayed and it appears to be moving.

A for loop is constructed to move an x in every LCD position.

For loops can be nested to cycle in a multidimensional way.

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.

Soldering a wire to a metal pin of a header is tricky. The problem with simply soldering a wire to a metal pin is that the wire can easily break off of the pin. The solution is to create a mechanical connection with the wire to the pin and then soldering the wire. A mechanical connection in this case is simply taking the wire and looping it once around the pin.

Extra hands are used to assist in the holding of the headers while soldering

Servos are motors that use feedback to control the motor's position. This type of control is called closed loop control. Servos use a special electromechanical device to provide this feedback. This electromechanical device can be a potentiometer or encoder. Encoders come in various shapes, sizes and resolutions.

Encoders provide a pulse (usually caused by an LED and sensor) that determines the position of the shaft of the motor. When the controller counts to the commanded number of pulses, the motor is stopped, or put into reverse if the motor over ran the position. The motor and controller will constantly provide torque in the direction that is needed to keep the position and is always correcting.

If a potentiometer is used, the motor shaft is connected to the potentiometer in some way (hobby servos connect the potentiometer with gears).

Encoders are devices that are used in the closed loop control of motors. Encoders provide the control system the feedback on where the motor is positioned. Encoders can be linear, or radial. If the encoder is physically connected to the motor shaft in some way, then the encoder is generally circular containing some type of transparency that would provide a pulse if turned. The pulse is generated by a light on one side of the encoder and a sensor on the other side of the encoder.

If the encoder is not physically connected to the motor shaft, then the encoder may be a linear strip (commonly called a code strip). The light and sensor would be connected near the motor and the code strip would be tied the extremes of where the motor will travel.

The OCR1A for the first position is moved into the while(1) never ending loop. A delay is introduced because it takes time for the servo to get to the intended position. If the delay was not used, the servo would just shake in a very small position. Also, since there is no way for the microcontroller to know the position of the servo (all of the closed loop positioning is internal within the servo) the delay allows the servo to reach the position.

Another OCR1A for the other extreme position is added after the delay. Another delay is added after this statement to give the servo time to get to this new position.

The process is repeated until the microcontroller is unplugged.

The values are 800 (.8 ms) and 2200 (2.2 ms). These numbers can be further tweaked to turn the horn more towards its limits.

The OCR1A for the first position is moved into the while(1) never ending loop. A delay is introduced because it takes time for the servo to get to the intended position. If the delay was not used, the servo would just shake in a very small position. Also, since there is no way for the microcontroller to know the position of the servo (all of the closed loop positioning is internal within the servo) the delay allows the servo to reach the position.

Another OCR1A for the other extreme position is added after the delay. Another delay is added after this statement to give the servo time to get to this new position.

The process is repeated until the microcontroller is unplugged.

A state machine is simply a sharing of the microcontrollers processing time. A state machine is like a loop that considers certain processes within a program and does this in a way that the processes get certain priorities if desired.