// GPIO.c UPIITA-IPN
// JOSE DAVID VALENCIA PESQUEIRA
//
// THIS PROGRAM ALLOWS THE DSP TO SEND A BIT THROUGH A GPIO PIN (PIN 7 IN THIS EXAMPLE)
// TO TURN ON A LED ON
#include <stdio.h>
#include <stdlib.h>
#include <csl_gpio.h>
#include <csl_gpiohal.h>
#include <csl_irq.h>
// GLOBAL VARIABLES
volatile int flag = 1;
volatile int pulse_flag = 1;
// CODE TO DEFINE GPIO HANDLE
GPIO_Handle gpio_handle;
// GPIO REGISTER CONFIGURATION
GPIO_Config gpio_config = {
0x00000000, // gpgc = Interruption passthrough mode
0x0000FFFF, // gpen = All GPIO 0-15 pins enabled
0x0000FFFF, // gdir = All GPIO pins as outputs
0x00000000, // gpval = Saves the logical states of pins
0x00000000, // gphm All interrupts disabled for IO pins
0x00000000, // gplm All interrupts for CPU EDMA disabled
0x00000000 // gppol -- default state */
};
// Function prototypes
void send_edge();
void delay();
// Function definitions
void delay()
{
// Delay function
int count, count2;
for(count = 0; count < 200; count++)
{
for(count2 = 0; count2 < 50000; count2++);
}
}
void send_edge()
{
DSK6713_init();
// Open and configure the GPIO
gpio_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );
GPIO_config(gpio_handle,&gpio_config);
// Send values through the pins
GPIO_pinWrite(gpio_handle,GPIO_PIN7,0);
delay();
GPIO_pinWrite(gpio_handle,GPIO_PIN7,1);
delay();
GPIO_pinWrite(gpio_handle,GPIO_PIN7,0);
}
main()
{
send_edge(); // Configures the pins and sends a rising edge
printf(“ ¡Felicidades! ¡Has logrado encender el led! ”);
}
// End of program>>
/* Interruption.c
JOSE DAVID VALENCIA PESQUEIRA
UPIITA-IPN
THIS PROGRAM DETECTS AN EXTERNAL INTERRUPTION ON A GPIO PIN*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <csl_gpio.h>
#include <csl_gpiohal.h>
#include <csl_irq.h>
/* GLOBAL VARIABLES
The flags are marked as volatile, to tell the compiler
that these can be modified by an external event, avoiding
to put them on registers and rather putting them on RAM
so they're ready for immediate use
*/
volatile int startflag = 0;
GPIO_Handle gpio_handle; /* Handle for the GPIO */
// GPIO Registers configuration
GPIO_Config gpio_config = {
0x00000000,
// gpgc = Interruption passtrhrough mode and direct GPIO control mode
0x0000FFFF, // gpen = All GPIO 0-15 pins enabled
0x00000000, // gdir = All GPIO pins as inputs
0x00000000, // gpval = Stores logical level of pins
0x00000010, // IRQ enable for pin 4
0x00000010, // Enable Event for pin 4
0x00000000 // gppol -- default state
};
irq_ext_enable(){
/* First, globally disable interruptions
in the CSR (Control Status Register).
Bit 0 is the GIE (Global Interrupt Enable)*/
CSR = (CSR)&(0xFFFFFFFE);
// Enable NMIE bit in the IER (bit 1)
IER |= 0x00000002;
// Enable INT4 bit in the IER (4th bit)
IER |= 0x00000010;
// Finally, globally enable interruptions in the CSR
CSR |= 0x00000001;
}
main()
{
// To configure the GPIO
gpio_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );
GPIO_config(gpio_handle,&gpio_config);
irq_ext_enable();
comm_intr(); //init DSK
DSK6713_LED_init();
while(startflag == 0);
printf(“La interrupción externa encendió el led 3 del dsk6713\n”);
while(1) // Infinite While
}
interrupt void c_int04() //ISR
{
startflag = 1;
iter = 0;
DSK6713_LED_on(0); //To turn on the led
}
//Continuous Time Fourier Series Spectral Coefficients of
//a periodic Cosine signal x(t) = cos(Wot)
clear;
close;
clc;
t = 0:0.01:1;
T = 1;
Wo = 2*%pi/T;
xt = cos(Wo*t);
for k =0:5
C(k+1,:) = exp(-sqrt(-1)*Wo*t.*k);
a(k+1) = xt*C(k+1,:)'/length(t); //fourier series is done
if(abs(a(k+1))<=0.01)
a(k+1)=0;
end
end
a =a';
ak = [a($:-1:1),a(2:$)];
disp(ak,'Continuous Time Fourier Series Coefficients are:')
//Result
//Continuous Time Fourier Series Coefficients are:
// column 1 to 11
// 0 0 0 0 0.5049505+1.010D-18i 0 0.5049505-1.010D-18i 0 0 0 0
//Generation of Differential Phase shift keying signal
clc;
bk = [1,0,1,1,0,1,1,1];//input digital sequence
for i = 1:length(bk)
if(bk(i)==1)
bk_not(i) =~1;
else
bk_not(i)= 1;
end
end
dk_1(1) = 1&bk(1); //initial value of differential encoded sequence
dk_1_not(1)=0&bk_not(1);
dk(1) = xor(dk_1(1),dk_1_not(1))//first bit of dpsk encoder
for i=2:length(bk)
dk_1(i) = dk(i-1);
dk_1_not(i) = ~dk(i-1);
dk(i) = xor((dk_1(i)&bk(i)),(dk_1_not(i)&bk_not(i)));
end
for i =1:length(dk)
if(dk(i)==1)
dk_radians(i)=0;
elseif(dk(i)==0)
dk_radians(i)=%pi;
end
end
disp(bk,'(bk)')
bk_not = bk_not';
disp(bk_not,'(bk_not)')
dk = dk';
disp(dk,'Differentially encoded sequence (dk)')
dk_radians = dk_radians';
disp(dk_radians,'Transmitted phase in radians')
#define COMB_FILTER_ORDER 3 // Filter Order, i.e., M
#define DELAY_ARRAY_SIZE 9 // Number of (delayed) input samples to store
int filtersum; // Sum-of-products accumulator for calculating the filter output value
int delay[DELAY_ARRAY_SIZE]; // Array for storing (delayed) input samples
static int gain1 = 1;
static int gain2 = 4;
interrupt void isr() //Interrupt service routine
{
short i; // Loop counter
delay[0] = get_sample() / gain1; // Read filter input sample from ADC and scale the sample
filtersum = delay[0]; // Initialize the accumulator
for (i = COMB_FILTER_ORDER; i > 0; i--)
{
filtersum += delay[i]; // Accumulate array elements
delay[i] = delay[i-1]; // Shift delay elements by one sample
}
filtersum *= gain2; // Scale the sum-of-products
send_output(filtersum); // write filter output sample to DAC
return; // interrupt servicing complete
}
void main()
{
short i; // loop counter
for (i=0; i< DELAY_ARRAY_SIZE; i++) // Initialize delay elements with 0
{
delay[i] = 0;
}
init_all(); // global initialization
while(1); // infinite loop
// do nothing except wait for the interrupt
}
clf;
% First plot
t = 0:0.0005:1;
f = 5;
x_t = cos(2*pi*f*t);
subplot (4,1,1);
plot (t,x_t);
grid;
xlabel ('Time [sec]');
ylabel ('Amplitude');
title ('Continuous-time signal x(t)');
axis([0 1 -1.2 1.2])
% Second plot
n = 0:0.125:1;
x_n = cos(2*pi*f*n);
subplot(4,1,2);
y = zeros(1,length(t));
for i = 1:length(n)
y = y + x_n(i)*sinc(t/0.125 - i + 1);
end
plot(t,y);
grid;
xlabel ('Time, sec');
ylabel ('Amplitude');
title ('Reconstructed continuous-time signal y(t) [fs < bound] (T=0.125)');
axis ([0 1 -1.2 1.2]);
% Third plot
n = 0:0.1:1;
x_n = cos(2*pi*f*n);
subplot(4,1,3);
y = zeros(1,length(t));
for i = 1:length(n)
y = y + x_n(i)*sinc(t/0.1 - i + 1);
end
plot(t,y);
grid;
xlabel ('Time, sec');
ylabel ('Amplitude');
title ('Reconstructed continuous-time signal y(t) [fs = bound] (T=0.1)');
axis ([0 1 -1.2 1.2]);
% Fourth plot
n = 0:0.075:1;
x_n = cos(2*pi*f*n);
subplot(4,1,4);
y = zeros(1,length(t));
for i = 1:length(n)
y = y + x_n(i)*sinc(t/0.075 - i + 1);
end
plot(t,y);
grid;
xlabel ('Time, sec');
ylabel ('Amplitude');
title ('Reconstructed continuous-time signal y(t) [fs > bound] (T=0.075)');
axis ([0 1 -1.2 1.2]);
function [] = SineSweep(fstart, fstop, length, method, fs, bits, PHI)
%SINESWEEP Creates a custom sine wave sweep.
% SineSweep(fstart, fstop, length, [method], [fs], [bits], [PHI])
% fstart (Hz) - instantaneous frequency at time 0
% fstop (Hz) - instantaneous frequency at time length
% length (s) - the length of time to perform the sweep
% method - 'quadratic', 'logarithmic', or 'linear' (default)
% fs (Hz) - the sampling frequency (default = 48KHz)
% bits - bit depth of each sample 8, 16 (default), 24, or 32
% PHI (deg) - initial phase angle. cos = 0, sin = 270 (default)
%
% Written by: Ron Elbaz
% Date: February 15, 2011
%check and set missing parameters
if exist('method','var') ~= 1
method = 'linear';
end
if exist('fs','var') ~= 1
fs = 48000;
end
if exist('bits','var') ~= 1
bits = 16;
end
if bits ~= 8 && bits ~= 16 && bits ~= 24 && bits ~= 32
bits = 16;
end
if exist('PHI','var') ~= 1
PHI = 270;
end
%make sure start and stop frequencies are valid
if fstop < fstart
temp = fstart;
fstart = fstop;
fstop = temp;
end
%avoid aliasing
if fstart > fs/2
fstart = fs/2;
end
if fstop > fs/2
fstop = fs/2;
end
%create time vector
t = 0:(1/fs):length;
%scale to avoid clipping due to rounding error
Y = 0.9999*chirp(t,fstart,length,fstop, method, PHI);
%play the sound
% sound(Y,fs);
%store sweep to wav file
wavwrite(Y,fs,bits,'SineSweep.wav');
end
//Generation of Differential Phase shift keying signal
clc;
bk = [1,0,1,1,0,1,1,1];//input digital sequence
for i = 1:length(bk)
if(bk(i)==1)
bk_not(i) =~1;
else
bk_not(i)= 1;
end
end
dk_1(1) = 1&bk(1); //initial value of differential encoded sequence
dk_1_not(1)=0&bk_not(1);
dk(1) = xor(dk_1(1),dk_1_not(1))//first bit of dpsk encoder
for i=2:length(bk)
dk_1(i) = dk(i-1);
dk_1_not(i) = ~dk(i-1);
dk(i) = xor((dk_1(i)&bk(i)),(dk_1_not(i)&bk_not(i)));
end
for i =1:length(dk)
if(dk(i)==1)
dk_radians(i)=0;
elseif(dk(i)==0)
dk_radians(i)=%pi;
end
end
disp(bk,'(bk)')
bk_not = bk_not';
disp(bk_not,'(bk_not)')
dk = dk';
disp(dk,'Differentially encoded sequence (dk)')
dk_radians = dk_radians';
disp(dk_radians,'Transmitted phase in radians')
function [c] = PCM_Encoding(x,L,en_code)
//Encoding: Converting Quantized decimal sample values in to binary
//x = input sequence
//L = number of qunatization levels
//en_code = normalized input sequence
n = log2(L);
c = zeros(length(x),n);
for i = 1:length(x)
for j = n:-1:0
if(fix(en_code(i)/(2^j))==1)
c(i,(n-j)) =1;
en_code(i) = en_code(i)-2^j;
end
end
end
disp(c)
//PN sequence generation
//Maximum-length sequence generator
//Program to generate Maximum Length Pseudo Noise Sequence
clc;
//Assign Initial value for PN generator
x0= 1;
x1= 0;
x2 =0;
x3 =0;
N = input('Enter the period of the signal')
for i =1:N
x3 =x2;
x2 =x1;
x1 = x0;
x0 =xor(x1,x3);
disp(i,'The PN sequence at step')
x = [x1 x2 x3];
disp(x,'x=')
end
m = [7,8,9,10,11,12,13,17,19];
N = 2^m-1;
disp('Table Range of PN Sequence lengths')
disp('_________________________________________________________')
disp('Length of shift register (m)')
disp(m)
disp('PN sequence Length (N)')
disp(N)
disp('_________________________________________________________')
// Hamming Weight and Hamming Distance
//H(7,4)
//Code Word Length = 7, Message Word length = 4, Parity bits =3
close;
clc;
//Getting Code Words
code1 = input('Enter the first code word');
code2 = input('Enter the second code word');
Hamming_Distance = 0;
for i = 1:length(code1)
Hamming_Distance =Hamming_Distance+xor(code1(i),code2(i));
end
disp(Hamming_Distance,'Hamming Distance')
//Result
//Enter the first code word [0,1,1,1,0,0,1]
//Enter the second code word[1,1,0,0,1,0,1]
//Hamming Distance 4.