10 years, 9 months ago.

Pulse generation - How to create pulses in the form of sine waveforms?

Hello. I wrote this MATLAB code that is set to control an analogue circuit with transmission gates and it is supposed to be sending pre-defined pulses to the output. I was given the equivalent code in c, and saved it on the mBed and run it using teraterm and seems to be working perfectly. When Im tesing this code in MATLAB though the same results are not being obtained and pulses dont appear at the scope. On the mbed I have saved the RPC_Serial_LPC1768.bin file. Im really new to this and I cant figure out what it is that I am doing wrong. Any help would be appreciated. Thank you.

import mbed.*

delete(instrfind({'Port'},{'COM3'}))

mymbed = mbed.SerialRPC('COM3',9600);

mymbed.reset;

myled1 = DigitalOut (mymbed,LED1);

myled2 = DigitalOut (mymbed,LED2);

myled3 = DigitalOut (mymbed,LED3);

myled4 = DigitalOut (mymbed,LED4);

Mread = AnalogIn (mymbed,p16);

control = AnalogOut (mymbed,p18);

progM = DigitalOut (mymbed,p17);

readM = DigitalOut (mymbed,p26);

biasM = DigitalOut (mymbed,p20);

startV = DigitalOut (mymbed,p21);

startV2 = DigitalOut (mymbed,p22);

start = DigitalIn (mymbed,p23);

a=1;

while a == 1

%Voltage subtractor parameters

midPoint = 0.525; %Outputs 0V

readOut = 0.549; %Outputs 0.5V for reading

gainFront = 6.6; % Gain of the subtractor amp

gainBack = 5.973793; %Gain of the Mread amp

%Define mBed parameters

startV.write(1);

startV2.write(1);

triggerEnd=(0);

i=(0);

counter=(1);

Y=0.5;

Rm=150000;

pulse=ones(1,5000);

myled1.write(0);

myled2.write(1);

myled3.write(1);

myled4.write(0);

%Initialize the transmission gates to be closed

progM.read(); progM.write(0);

biasM.read(); biasM.write(0);

readM.read(); readM.write(0);

%Sine wave parameters

frequency = 1;

pulsewidth = 0.001;

pulsenr = 50;

amplitude = 5;

%Main Loop

if (start.read() == 0)

triggerEnd=0;

counter=0;

control.read();

control.write(midPoint);

end

%Waveform generator

for i = 1 : 1 : pulsenr

%Display

myled1.write(1);

myled4.write(1);

pause(0.005);

myled1.write(0);

myled4.write(0);

pause(0.005);

pulse(i)=sin(2*3.14*i*frequency/pulsenr);

end

%Read sequence

control.write(readOut);

pause(0.01);

biasM.write(1);

readM.write(1);

pause(0.01);

for i=0:1:20

X=(1/gainBack)*3.3*Mread.read/20;

end

readM.write(0);

biasM.write(0);

control.write(midPoint);

Mnow=Rm*X/(Y-X);

while ((start.read() == 1) && (triggerEnd == 0))

%READ sequence

control.write(readOut);

pause(0.01);

biasM.write(1);

readM.write(1);

X=0;

pause(0.01);

for i=0:1:20

X=(1/gainBack)*3.3*Mread.read/20;

end

readM.write(0);

biasM.write(0);

control.write(midPoint);

Mnow=Rm*X/(Y-X);

%PULSE sequence

U=midPoint+amplitude*pulse(counter)/(3.3*gainFront);

control.write(U);

pause(0.01);

progM.write(1);

pause(pulsewidth);

progM.write(0);

control.write(midPoint);

if (counter == pulsenr-1)

triggerEnd=1;

counter=counter+1;

end

end

break

end

mymbed.delete;

Be the first to answer this question.