Commit 1b1868b0 authored by Stewart Thomas's avatar Stewart Thomas
Browse files

Adds homework binaries

parent 6d6456e7
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p1 = 50 * [.2 - j*0.5];
h = plotz(p1, 'o');
set(h, 'markersize', 18, 'linewidth', 6)
p1e = 50 * [.2 + 1j*2];
h = plotz(p1e, 'x');
set(h, 'markersize', 18, 'linewidth', 6)
% Ans: use SERIES INDUCTOR
%%
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p2 = 50 * [.5 + j*.5];
h = plotz(p2, 'o');
set(h, 'markersize', 18, 'linewidth', 6)
p2e = 50 * [1 - 1j];
h = plotz(p2e, 'x');
set(h, 'markersize', 18, 'linewidth', 6)
% ans: series l, shunt l
%%
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p3 = 50 * [2 + 1j*5];
h = plotz(p3, 'o');
set(h, 'markersize', 18, 'linewidth', 6)
p3e = 50 * [.25 - .25j];
h = plotz(p3e, 'x');
set(h, 'markersize', 18, 'linewidth', 6)
% series l, shunt c, load
%%
%% PROBLEM 1:
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p1 = 50 * [.2 - j*0.5];
h = plotz(p1, 'o');
set(h, 'markersize', 12, 'linewidth', 2)
p1e = 50 * [.2 + 1j*2];
h = plotz(p1e, 'x');
set(h, 'markersize', 12, 'linewidth', 2)
%% PROBLEM 2:
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p2 = 50 * [.5 + j*.5];
h = plotz(p2, 'o');
set(h, 'markersize', 12, 'linewidth', 2)
p2e = 50 * [1 - 1j];
h = plotz(p2e, 'x');
set(h, 'markersize', 12, 'linewidth', 2)
%% PROBLEM 3:
figure(1);clf;
smithchart([1, 0, 0], 1);
set(gca, 'xdir', 'reverse');
hax = axes();
smithchart();
p3 = 50 * [2 + 1j*5];
h = plotz(p3, 'o');
set(h, 'markersize', 12, 'linewidth', 2)
p3e = 50 * [.25 - .25j];
h = plotz(p3e, 'x');
set(h, 'markersize', 12, 'linewidth', 2)
This diff is collapsed.
//******************************************************************************
// MSP430F2011 Program
//
// 2.5 kHz Generator
//
// The program outputs an annoying tone
//
//******************************************************************************
//Which one to include???
#include <msp430x20x2.h>
#include <msp430x20x1.h>
/*unsigned char a; // 1 byte = 8 bits
unsigned short b; // 2 bytes = 16 bits
unsigned long c; // 4 bytes = 32 bits
*/
void main(void)
{
unsigned short icounter; // counter for beeper loop
// Disable Entire System
// _BIS_SR(LPM4_bits);
/* Don't worry about this */
// Turn DCO to slowest clock (method from Errata sheet)
DCOCTL = 0x00;
// Set RSEL bits
BCSCTL1 &= 0xF0; // 0b1111_0000 -> Clear out previous setting
/*BCSCTL1 |= 0x00; // Place new setting for RSEL : 0b0000_xxxx
DCOCTL |= 0x00; // Place new setting for DCO : 0bxxx0_0000*/
BCSCTL2 |= DIVM0; //Divide MCLK by 2
/* Ok, back to worrying */
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Set P1.ALL to be Output ports
P1OUT = 0x00;
P1DIR |= BIT2; // Make beeper an output port
while (1){
// Generate ?? kHz tone -- Tone 1
for ( icounter = ??? ; icounter >= 0 ; icounter-- ) {
// Toggle Pin ON
P1OUT ^= BIT2;
// Delay for 1/2 period of 2.5 kHz (10 cycles)
//__delay_cycles(1);
// Toggle Pin OFF
P1OUT ^= BIT2;
// Delay
__delay_cycles(1); // a macro to delay for some number of cycles
}
}
}
%%
figure(1);clf;
linc = [.125, .125, .125]; % line color
% plot real line
x = [-1, 1];
y = [0, 0];
plot( x, y , 'color', linc);
axis equal;
axis off;
hold on;
if 0
r = ones(1, 500) * 0;
x = linspace(-1000, 1000, 500);
z = complex(r, x) ./ 50;
g = (z - 1) ./ (z + 1);
plot(real(g), imag(g));
end
% plot constant resistance
for R = [0, 10, 25, 50, 100, 200]
r = R/50;
rad = 1/(r + 1);
cent = 1-rad;
th = linspace(0, 2*pi, 500);
plot(rad*cos(th) + cent, rad*sin(th), 'color', linc)
end
if 0
r = linspace(0, 1000, 500);
x = ones(1, 500) * -10;
z = complex(r, x) ./ 50;
g = (z - 1) ./ (z + 1);
plot(real(g), imag(g));
end
% plot constant reactance
for X = [10, 25, 50, 100, 200]
x = X/50;
rad = 1/(x);
cent = rad;
th = 2 * atan(x) * linspace(0, 1, 500);
plot(1 - rad*sin(th), cent - rad*cos(th), 'color', linc);
plot(1 - rad*sin(th), -cent + rad*cos(th), 'color', linc);
end
% ADD TEXT
% Make function!
%%
l = 54e-9;
c = .45e-12;
w = 2 * pi * 915e6;
zs = 50 + 1j*w*l + 1/(1j*w*c);
gs = (zs - 50) / (zs + 50);
gss = conj(gs);
plot(real(gss), imag(gss), 'x')
%%
ltest = 22;
l = ltest * 1e-9;
z1 = 1/(1j*w*1e-12) + 15 + 1j*w*l;
z2 = 1j*w*6e-9;
zl = (z1 * z2) / (z1 + z2);
gl = (zl - 50) / (zl + 50);
plot(real(gl), imag(gl), 'o')
\ No newline at end of file
%create a vector for capacitance. Vary it from say, 0.5pF up to 10 pF
c = linspace(0.05e-12, 50e-12, 500);
% choose a frequency
f = 915e6; % 915 MHz
% form the reactance (X in Z = R + jX)
w = 2 * pi * f;
X = -1j ./ (w * c);
% define an R variable for the resistor
R = 22;
% form Z which is the parallel combination of R and C
Zp = 1 ./ ( (1 ./ X) + (1 ./ R) );
% or
%Zp = (R * X) ./ (R + X);
% Then calculate gamma
z0 = 50; % characteristic impedance
gamma = (Zp - z0) ./ (Zp + z0);
figure(1);clf;
smithchart()
plot(real(gamma), imag(gamma))
\ No newline at end of file
//******************************************************************************
// MSP430F201x Program
//
// Beep Generator
//
// The program sleeps for ??? ms in LPM3 mode, then wakes up and outputs
// a ??? kHz square wave tone on P1OUT1.? for ??? ms
//
//******************************************************************************
#include <msp430x20x1.h>
// #include <msp430x20x2.h>
/*unsigned char mask2; // 1 byte = 8 bits
unsigned short position; // 2 bytes = 16 bits
unsigned long data; // 4 bytes = 32 bits
*/
void main(void)
{
//PLAN:
// 1) set clock to low setting
// 2) Set pins to be Input/output
// 3) Set ACLK to be sourced from VLOCLK
// 4) Sleep for a short period (~20 ms)
// 5) Enter loop
// a) beep
// b) sleep for a long period
// c) Wake up!
// d) repeat
//END OF PLAN
int i;
// Turn DCO to slowest clock (method from Errata sheet)
DCOCTL = 0x00;
// Set RSEL bits
BCSCTL1 &= 0xF0; // 0b1111_0000 -> Clear out previous setting
/*BCSCTL1 |= 0x00; // Place new setting for RSEL : 0b0000_xxxx
DCOCTL |= 0x00; // Place new setting for DCO : 0bxxx0_0000*/
BCSCTL2 |= DIVM0; //Divide MCLK by 2
// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
// Turn OFF SMCLK and external Oscillator
// OSCOFF : ?
// SCFG1 : ?
_BIS_SR(OSCOFF + SCG1);
// Set P1.ALL to be Output ports
P1OUT = 0x00;
P1DIR = 0xFF;
P1SEL = 0x00;
// Setup ACLK source to be from internal VLOCLK (~10 kHz)
BCSCTL3 |= LFXT1S_2;
// Setup ACLK to be dvided by 8 (~10 kHz / 8 => ~.8 ms per clock tick)
BCSCTL1 |= DIVA1 + DIVA0;
// Sleep ~20 ms
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 25; // 10 khz/8 source * 20 ms = 25 cycles
TACTL = TACLR + TASSEL_1 + MC_1; // Clear TA0, Source: ACLK, Mode: UP
// Enter LPM3 Mode
_BIC_SR(OSCOFF); // Turn on VLOCLK
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
// -- Wake up -- //
// Turn OFF SMCLK and external Oscillator
_BIS_SR(OSCOFF + SCG1);
while (1) {
// Generate 5.0 kHz tone -- Tone 1
for ( i = 175 ; i > 0 ; i-- ) {
// Toggle Pin ON
P1OUT |= BIT2;
// Delay for 1/2 period of 2.5 kHz (10 cycles)
//__delay_cycles(1);
// Toggle Pin OFF
P1OUT &= ~(BIT2);
// Delay
__delay_cycles(2);
}
// Sleep ??? ms
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = ???; // 10 khz / 8 source * ??? ms = ?,??? cycles
TACTL = TACLR + TASSEL_1 + MC_1; // Clear TA0, Source: ACLK, Mode: UP
// Enter LPM3 Mode
_BIC_SR(OSCOFF);
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
// -- Wake up -- //
// Turn OFF SMCLK and external Oscillator
_BIS_SR(OSCOFF + SCG1);
}
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
{
// Turn timer interrupts OFF
CCTL0 = 0x00;
// Turn OFF Timer
TACTL = 0x00;
// Turn CPU on
_BIC_SR_IRQ(LPM3_bits + GIE);
}
function smithchart(line_color, hide_text)
% Prints a Smithchart to the screen
%figure(1);clf;
if (nargin < 2)
hide_text = 0;
end
if ((nargin < 1) || isempty(line_color))
linc = [.125, .125, .125]; % line color
else
linc = line_color;
end
% plot real line
x = [-1, 1];
y = [0, 0];
plot( x, y , 'color', linc);
axis equal;
axis off;
hold on;
% plot constant resistance (uses circle method)
for R = [0, 10, 25, 50, 100, 250]
r = R/50;
rad = 1/(r + 1);
cent = 1-rad;
th = linspace(0, 2*pi, 500);
plot(rad*cos(th) + cent, rad*sin(th), 'color', linc)
end
% plot constant reactance (uses circle method)
for X = [10, 25, 50, 100, 250]
x = X/50;
rad = 1/(x);
cent = rad;
th = 2 * atan(x) * linspace(0, 1, 500);
plot(1 - rad*sin(th), cent - rad*cos(th), 'color', linc);
plot(1 - rad*sin(th), -cent + rad*cos(th), 'color', linc);
end
%% Adds text
if (hide_text ~= 1)
topstr = {'+j0.2', '+j0.5', '+j1', '+j2', '+j5'};
botstr = {'-j0.2', '-j0.5', '-j1', '+j2', '-j5'};
top = [-1.2, .38
-.85, 0.85
-.1, 1.1
0.6, 0.9
0.9, 0.5];
bot = [top(:, 1), -1*top(:, 2)];
realstr = {'0', '0.2', '0.5', '1', '2', '5', '\infty'};
real = [-1.1, 0
-.72, .05
-.42, .05
0, .05
1/3, .05
.6, .05
1.05, .02];
coords = [top; bot; real];
str = [topstr(:); botstr(:); realstr(:)];
for n = 1 : length(coords)
text(coords(n, 1), coords(n, 2), str(n), 'fontsize', 10)
end
end
end
% closes function
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment