Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC to matlab interface

Status
Not open for further replies.

hisham.i

Newbie level 5
Joined
Oct 25, 2010
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
Hello
I am trying to make an interface between pc and pic16f877A, which allows me to switch a led on and off using a push button.
i made the gui in matlab and programed the bushbutton, and then i wrote the microcontroller program, but while i was simulating it in proteus nothing happens, i didn't recognize the problem.
Also if i press the push button data should be sent to TX pin in the serial port but i recognize that it is sent to CTS pin!
this is my matlab call back connected to the push button:

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clear all;
s=serial('COM1');
set(s,'baudrate',9600);
fopen(s);
fprintf(s,'%d','h');
fclose(s);
delete(s);
clear s;
 


I trid your code but nothing changed, matlab gives this error

??? Error using ==> serial.fopen at 71
Cannot connect to the COM1 port. Possible reasons are another
application is connected to the port or the port does not exist.

I don't have a physical serial port in my laptop, but i downloaded a virtual serial port driver and create 2 virtual ports, but the error doesn't changed.
 

Sorry....I have can't hlep you there..but what is the point of using Matlab iwth PIC16F877A...???? I mean, whtat can you acheive by doing that..?????
 

Am trying to turn a led on and off from the computer, this is done using a serial port interface between the computer and the microcontroller which will take the decision to what to do according to the data transmitted from the serial port.
 

Try using a USB to serial port converter hardware.
Does the ports that you create are shown by the device manager?
I faced a similar problem with matlab using actual hardware and each time i had to close matlab to solve the problem of "device in use"
I suggest Labview software for such experiments.
The easiest way is to send the command through the terminal which is available in proteus.
Regards.
 

I trid your code but nothing changed, matlab gives this error

??? Error using ==> serial.fopen at 71
Cannot connect to the COM1 port. Possible reasons are another
application is connected to the port or the port does not exist.

I don't have a physical serial port in my laptop, but i downloaded a virtual serial port driver and create 2 virtual ports, but the error doesn't changed.

It is better if you can check your code in a PC which has physical serial port (first choice).
 

Yes waseem the devices are shown in the device manager when i add the virtual ports, proteus also has a serial port block so you can interface between different programs.
I'll try it in a computer which has a physical serial port, to see if things will change.
 

Hi hisham!
Well i tried the virtual port concept with proteus and matlab and it worked perfectly for me.
Here is what i did.
1. Downloaded a virtual port creator from this site **broken link removed**.
2. This software creates virtual ports in pairs. e.g if you create COM3 and COM4 then they are always virtually connected to each other. So that if you transmit data on COM3
then it is automatically received on COM4.
3. I opened a new file in proteus and added the component COMPIN which simulates a serial port. In the properties of this component i selected COM4. Also set both the virtual
and physical baudrates to 9600. In proteus i took a virtual terminal and connected its RX pin to the RX pin of the COMPIM. Also set the baudrate of this terminal to 9600.
4. I opened COM3 in matlab and transmitted the following characters using the code below.

s = serial('COM3','BaudRate',9600);
>> fopen(s);
>> fprintf(s,'A');
>> fprintf(s,'A');
>> fprintf(s,'A');
>> fprintf(s,'A');
>> fprintf(s,'A');
5. The terminal in Proteus correctly received and displayed the data.
6. In your project instead of connecting the COMPIM to a terminal you can connect it to a micro-controller which can then receive the data from matlab.
 
:D thank you waseem the problem was in this part, because i used COM1 in both matlab and proteus so because of this matlab shows me that the port is used by another softawre, when i changed the port in proteus to COM2 the data transferred successfully:D
 

You are welcome.
Thats normal.
Still, all is well that ends well.
Regards.
 

Hey guys i am new here!!!
Ubaid student of Bsc Electronics

any boday will teach me how can i turn on and off 3 diffrent colurs of leds by giving delays on input by matlab and leds are conected via a serial port.

i dnt know anything abt this so please describe in easy words
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top