Tag Archives: homework

Blinking lights MSP430 FG461x

Photo of two experimenter boards for the MSP43...

Image via Wikipedia

I have been working on MSP430 for sometime now. It is an TI (Texas Instruments ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles one may need to create any application from a home automation controller to a simple step-motor driver. TI provides very good documentation for this grown up toy.

Our first lab homework for this baby was :

By using the MSP430 FG4618 Microcontroller, write a program that controls the LED #1, #2,#4.When we perpetually push the two buttons at the right bottom corner of the board, all ofthe LEDs turn on.When we push perpetually one of the buttons, only the LED #4 blinks, the others turn off.When we push no buttons, the LED #1 and #2 blinks complementarily and the LED#4 turnsoff.

My biggest problem with this exercise was to find what led was connected to what port. However in the end I figured it all out.

Below you will find the program :

 

 

#include <msp430xG46x.h>

void initPortPins(void);

void main(void)
{ 
	 WDTCTL=WDTPW + WDTHOLD;
	 initPortPins(); 
	 while(1) {				  
	 	if (P1IN == (0x00))
	 	{
			P2OUT |= 0x06;
			P5OUT |= 0x02;
		}
		else if (P1IN == 0x03)
		{
			P2OUT &= 0x00;
			P5OUT &= 0x00;
			P2OUT |= 0x02;               					   
			__delay_cycles (40000);
			P2OUT &= 0x00;
			P2OUT |= 0x04;
			__delay_cycles (40000);
		}                                                                  
		else 
		{
			P2OUT &= 0x00;
			P5OUT &= 0x00;
			__delay_cycles (40000);
			P5OUT |= 0x02;
			__delay_cycles (40000);
		}
	 }
};

void initPortPins(void)
{
  P1DIR = 0x00;	// Set P2.2,1 as outputs
  P5DIR = 0x02; // Set P5.1 as output
  P2DIR = 0x06; // Set P2.1 to 1
};

Plotting and finding the magnitude of a wav file in MATLAB[edited]

Edited: Changed code to a more correct version!
The question was;

Load the file sound1.wav(Download from here => SoundWav (419) ) (You would use MATLAB command ‘wavread’ to loadthis file. Use MATLAB help to learn the usage of ‘wavread’). This file contains a portion of speech waveform. Take the first 512 point the signal, plot the waveformand its magnitude spectrum.

 
%call it like question_8('sound1.wav')
function question_8(url)
[x,fs]=wavread(url);
new_x=x(1:512);
subplot(2,1,1);
stem(new_x);
title('The sampled sound signal');
xlabel('time'), ylabel('amplitude');
grid on;
hold on


subplot(2,1,2)
N=(fs/2)*linspace(-1,1,length(x));
stem(N,fftshift(abs(fft(new_x))));

title('Sampled signal at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;
end

Sampling of a Sinusoidal Signal and finding the DTFT [edited]

The question was :

Write a MATLAB function, x = SinSamples(A, w, θ, d, ws), that generates a discrete-time sinusoidal signal x[n] obtained by sampling x(t), (Assume that x(t) is a sinusoidal segment with amplitude A, frequency ω, phase θ and duration ), with sampling frequency ω_s.

function SinSamples(A,w,teta,d,w_s)

clc;
fprintf(' This program will read and sample a sin signal.\n The parameters are amplitude A , frequency w , phase "teta" and d for duration. \n This program was written for the Ele 409 DSP Lab course. \n By = John Roach \n\n');

pause(2);

f = w/(2*pi);
T = 1/f;
tmin = 0;
dt = T/100;
dt1 = 1/(w_s/(2*pi));
t = tmin:dt:d;
t1 = tmin:dt1:d;
x = A*sin(w*t+teta);
x1 = A*sin(w*t1+teta);
subplot(2,1,1);
plot(t,x,'r');
hold on
stem(t1,x1);
title('The sampled and original signal');
xlabel('frequency'), ylabel('amplitude');
grid on;
hold on

subplot(2,1,2)

N=(fs/2)*linspace(-1,1,length(x1));
stem(N,fftshift(abs(fft(x1))));
title('Sampled signal at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;

For sample code ;

SinSamples(1,2*pi*1000,pi/6,0.002,2*pi*16000)

The output is;

This program will read sample a sin signal. The parameters are amplitude A , frequency w , phase "teta" and d for duration.  This program was written for the Ele 409 DSP Lab course.  By = John Roach

and;