<< Chapter < Page Chapter >> Page >

This example shows what type of vector would be aquired if the DSP was constantly counting up and outputting these numbers. We are taking in vector of size 6 at some random point in the operation of the DSP: %In the MATLAB terminal: y = GetSerialData('com2', 38400, 6)y =7 8 9 10 11 12 The numbers are counting up as written in the C DSP code. We can also specify signed numbers and if we catch the counting at the right moment we get an output like this: y = getSerialData('com2', 38400, 6, 1) y =125 126 127 0 -1 -2

Got questions? Get instant answers now!

Other notes

Other functionality can be added to this code. This may include other serial port issues (such as handshaking or parity) or even the formatting of the data coming out of the dsp.For instance, to get numbers larger than bytes in each vector index, you can modify how data is written to the MATLAB vector when it is acquired in the Receive function (in the code).Code for modifying serial port abilities is commented in the main() function where the serial port handle is initialized.

Using matlab gui features

MATLAB has some nice Graphical User Interface (GUI) features which can be used to control the flow of data to and from the serial port. The basic implementation consits of a blank window (figure) which can have differentinterface elemnts palced on it. These elements can be sliders, buttons, text boxes, etc...

When an element is accessed (for instance, a slider is moved, or a button is pushed), MATLAB will execute a "callback routine" which is a MATLAB function defined by the user. Desgining these interfacesis simple.

Creating a user interface with sliders

1 % ser_set: Initialize serial port and create three sliders 23 % Set serial port mode 4 !mode com2:38400,n,8,15 6 % open a blank figure for the slider7 Fig = figure(1); 89 % open sliders 1011 % first slider 12 sld1 = uicontrol(Fig,'units','normal','pos',[.2,.7,.5,.05],... 13 'style','slider','value',4,'max',254,'min',0,'callback','wrt_slid');14 15 % second slider16 sld2 = uicontrol(Fig,'units','normal','pos',[.2,.5,.5,.05],...17 'style','slider','value',4,'max',254,'min',0,'callback','wrt_slid'); 1819 % third slider 20 sld3 = uicontrol(Fig,'units',normal','pos',[.2,.3,.5,.05],... 21 'style','slider','value',4,'max',254,'min',0,'callback','wrt_slid');
Got questions? Get instant answers now!

Lines 12 through the end create the three sliders for the user interface. Several parameters are used to specify the behavior of each slider. The first parameter,Fig, tells the slider to create itself in the window we created in Line 7. The rest of the parameters are property/value pairs:

  • units : Normal tells Matlab to use positioning relative to the window boundaries.
  • pos : Tells Matlab where to place the control.
  • style : Tells Matlab what type of control to place. slider creates a slider control.
  • value : Tells Matlab the default value for the control.
  • max : Tells Matlab the maximum value for the control.
  • min : Tells Matlab the maximum value for the control.
  • callback : Tells Matlab what script to call when the control is manipulated. wrt_slid is a Matlab file that writes the values of the controls to the serial port.
Every time a slider is moved, the wrt_slid.m file is called:

1 % wrt_slid: write values of sliders out to com port 23 % open com port for data transfer 4 fid = fopen('com2:','w');5 6 % send data from each slider7 v = round(get(sld1,'value')); 8 fwrite(fid,v,'int8');9 10 v = round(get(sld2,'value'));11 fwrite(fid,v,'int8'); 1213 v = round(get(sld3,'value')); 14 fwrite(fid,v,'int8');15 16 % send reset pulse17 fwrite(fid,255,'int8'); 1819 % close com port connection 20 fclose(fid);
Got questions? Get instant answers now!

Line 7 retrieves the value from the slider using the get function to retrieve the value property. The value is then rounded off to create an integer, and the integeris sent as an 8-bit quantity to the DSP in Line 8. (The number that is sent at this step will appear when the serial port is read with READSER or a C equivalent in your code.) The othertwo sliders are sent in the same way. Line 17 sends 0xFF (255) to the DSP, which can be used to indicate that the three previously-transmitted values represent a complete set of data points.This can be used to prevent the DSP and Matlab from losing synchronization if a transmitted character is not received by the DSP.

Line 20 closes the serial port. Matlab buffers the data being transmitted, and data is often not sent until the serial port is closed. Make sure you closethe port after sending a data block to the DSP.

Advanced features

The slider example shows some basic features of the gui tools. The file descriptor is generated into the workspace so that it can be used for writing. But other elements, such as text boxescannot be dealt with as easily. The Parameters from these can be accessed through their returned handles. Some examples:

%GUI.m %****Sample GUI, Text and a Button***%open a blank figure Fig = figure(1);set(Fig,'Name','Test GUI'); %Space to enter texted2 = uicontrol(Fig,'backgroundcolor','white','units','Normalized','pos',[.1,.6,.4,.05],...'string','Default Text','style','edit'); %Buttonbut1 = uicontrol(Fig,'foregroundcolor','blue','units','Normalized','pos',[.1,.4,.5,.1],...'string','Press Me!','style','pushbutton','callback','SampleGUI');

A Text box is created with default text in it that says: "Defaul Text". A button is also created, which when pressed, will execute the callback function SampleGUI.m

%SampleGUI.m %Get TexttestText = get(ed2,'string')

Now testText holds whatever string was enetered into the text box. The function get() is used to retrieve the data from the 'string; parameter in the ed2 handle. MATLAB help uicontrol gives the full list of options for interface elements.

Got questions? Get instant answers now!

Questions & Answers

do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Digital signal processing laboratory (ece 420). OpenStax CNX. Sep 27, 2006 Download for free at http://cnx.org/content/col10236/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing laboratory (ece 420)' conversation and receive update notifications?