MSP430 Timer Interrupt Example

MSP430G2553 TIMER INTERRUPT EXAMPLE

This example shows how the timer interrupts can be used to generate precision square waves.

Two interrupt vectors are associated with the 16-bit Timer_A module.

The TACCR0 CCIFG flag has the highest Timer_A interrupt priority and has a dedicated interrupt vector.

The TACCR1 CCIFG, TACCR2 CCIFG, and TAIFG flags are prioritized and combined to source a single interrupt vector. The interrupt vector register TAIV is used to determine which flag requested an interrupt.

Note: An external 4 MHz oscillator was used to clock the M430G2553.

 

TIMER 0 INTERRUPT OUTPUTS

 

TIMER 1 INTERRUPT OUTPUTS

 

END POST

MSP430 Encoder State Machine

This is a basic encoder state machine that can be used with the Texas Instruments EXP430G2553 Launchpad.

The program toggles LED2 (grn) when the encoder is rotated clockwise and toggles LED1 (red) when the encoder is rotated counterclockwise.

Additional code can be added to increment or decrement a timer register or other variable using an encoder. The code would be added where the if – else statements are located within the switch – case statement.

Example Here: http://saroselectronics.com/msp430-encoder-adjustable-pwm/

 

end post

 

 

DIY Optical Encoder

An optical encoder has some advantages over a mechanical encoder. One advantage is no bouncy or noisy electrical contacts that create false or extra pulses. Also, an optical encoder can operate at a higher rotation rate than a mechanical encoder.

I created a simple optical encoder from commonly available materials.

ENCODER HOUSING: I made the encoder housing from a 3/4 inch PVC pipe cap with a short length of 3/4 inch PVC pipe glued inside. The axle that supports the encoder disk was made from an inexpensive motor that I removed the magnets and the motor brushes from in order to allow the motor armature to spin freely.

The motor is then installed inside the PVC pipe. Since the fit was a little loose, I wrapped a couple of turns of tape around the body of the motor to make a tight fit. I also had to drill a small hole in the bottom end of the pipe cap to provide clearance for the rear motor bearing.

I sanded a flat spot on the outside of the pipe cap and drilled a small hole to accept a 4-40 flat head screw pointing out from the inside of the cap. This provides a threaded stud where the support for the encoder PCB is attached. The hole must be carefully located so that the opening in the photo-interrupters are at the correct level in relation to the encoder disk.

Finally I installed, with a press fit, a 1.5 inch diameter by 0.375 inch thick nylon disk to the motor shaft to which the encoder disk will be attached.

ENCODER CIRCUIT BOARD: I was able to fit the electronic components on a section of fiberglass circuit board that measured 1.375 inches by 1.625 inches. The photo-interrupters were located side by side and near the top edge of the PCB. The PCB also had a small hole drilled in it to allow mounting to the encoder support.

I installed two 0.1 inch spaced two position terminal blocks to facilitate the wire connections.

The encoder circuit uses two off-board 74HC14 Schmitt trigger inverters to clean up the pulses from the photo-interrupters and to drive two hi-efficiency blue indicator LEDs, one from each channel. This is not necessary for all applications.

The support for the encoder PCB was made from an approximately 1.25 inch long section of 0.375 diameter round nylon rod which was drilled and tapped at each end with a 4-40 thread.

ENCODER DISK: I designed the encoder disk by making a pattern using the spread sheet program Excel and then creating a pie chart with alternating black and white segments. The encoder pattern can be made with a variety of different diameters and with a different number of segments. It is important that the total number of segments used divide evenly into 360.

The artwork was printed out and then glued to a piece of thin cardboard with rubber cement. I used a compass to define the diameter of the disk and then cut it out with scissors. The notches at the edge of the disk were made with a 0.281 inch punch with the center of the hole located at the junction of the black and white segments.

This provides a total of 18 evenly spaced openings. The notches could also be cut out with a sharp x-acto knife instead of using a punch and cutting out the edge of either the white or black segment – but not both!

The finished disk was then glued to the nylon disk attached to the motor shaft.

The disk shown in the photos below had a diameter of 3.375 inches with a total of 36 segments – 18 black and 18 white.

More information on the encoder disk here: http://saroselectronics.com/create-encoder-pattern-using-excel/

 

PVC CAP WITH MOTOR AND MOUNTING STUD INSTALLED

 

ENCODER CIRCUIT BOARD

 

COMPLETED OPTICAL ENCODER WITHOUT DISK

 

COMPLETED OPTICAL ENCODER WITH DISK

 

ENCODER SCHEMATIC

 

CLOCKWISE PULSE OUTPUT FROM ENCODERS

 

COUNTER-CLOCKWISE PULSE OUTPUT FROM ENCODERS

 

End Post

MSP430 External Oscillator Code

CODE EXAMPLE TO CONFIGURE A MSP430G2553 FOR AN EXTERNAL OSCILLLATOR.

 

Adjustable DC Power Supply

This is a variable voltage analog power supply based on the LM317 adjustable voltage regulator. The LM317 includes on-chip current limiting, thermal overload protection, and safe operating area protection. All overload protection remains fully functional, even if the ADJUST terminal is disconnected.

The LM317 can output up to 2.2 amps, provided the difference between the input and output voltage is less than or equal to 15 VDC. The output current drops dramatically to 0.4 amps if the input-output difference is equal to 40 VDC. These values give an indication of the “safe operating area” protection.

The voltage is adjustable from 1.2 VDC to 30 VDC via a “VOLTS ADJ” potentiometer. There is also a “MAX ADJ” trim potentiometer that can be used to limit the maximum output voltage. The input is protected by a 1.8 Amp auto-reset fuse. Input voltage can be either 6-24 VAC or 8-35 VDC.

AC inputs are rectified by four 1N5402 (3 amp) diodes in a full bridge configuration and filtered by two 2200uF electrolytic capacitors. The main output regulator (TO-3 package) is fan cooled allowing continuous operation at high current levels and high ambient conditions. The regulator has built-in thermal protection and current limiting. The maximum output voltage is 30 VDC (with an input of 24 VAC or 35 VDC).

The two 6 inch diameter component mounting disks are made of 1/8 inch Delrin and the four 5/8 inch diameter support spacers are also made of Delrin.

The power transformer is a Triad F8-24 with a output of 24VAC at 4 Amps. A 1 amp fuse is installed on the transformer primary.

 

VERIFYING COMPONENT PLACEMENT

 

TOP AND BOTTOM COMPONENT TEMPLATES

 

TRANSFORMER AND TERMINAL BLOCK WIRING

 

COMPLETED POWER SUPPLY

 

1 AMP POWER SUPPLY PCB ARTWORK

 

 

END POST