MSP430 OLED Display Code

Program examples for the the Newhaven NHD-0216KZW-AG5 OLED display.

FUNCTION TO INITIALIZE OLED DISPLAY

FUNCTION TO SEND A SINGLE ASCII CHARACTER

FUNCTION TO SEND A CHARACTER STRING

FUNCTION TO CREATE A 10 BIT BIT-BANGED SPI

 

The entire program code for the PWM display will be published in a separate post.

End Post

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.