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.

MATLAB PIC Serial Communication

Status
Not open for further replies.

Jay_

Member level 3
Joined
Aug 23, 2010
Messages
56
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,288
Activity points
1,779
Hi guys,

I know there are similar threads but I wanted a direct help to my problem. I gave the other threads a read, but they didn't help me understand the solution to my task. I have two parts to this: 1. PIC program and 2. MATLAB code - both of these should coordinate. My understanding of MATLAB is not much as I am using it for the first time. I am using a PIC for the first time as well :D, but since I have used 8051 I can relate. The steps of what needs to be done are as follows:

1. IR sensor connected to pin pin 34 (RB1). This pin is normally high, when the object is placed it becomes low. WHILE it is low:

2. Webcam connected to USB of computer has to take a snap.

3. MATLAB code should generate RGB values of any pixel in the image (say center). Since I am using single colored objects (fully red,or blue or anything) the value of all pixels will be close.

4. PIC should enable communication through Rx and Tx through pins 26, 27.

5. Matlab code should send RGB values through DB-9 to MAX-232 which should go to PIC.

6. After PIC receives this data, it should disable communication through Rx and Tx.

--------------------------
7. I separate R, G, B values by ANDing the 3 byte code with FF0000 (then do right shifting 2 bytes), 00FF00 (then do right shifting 1 byte) and 0000FF respectively. Or I could do this in MATLAB itself, but I am afraid the data will get jumbled while transmittion.

If I can use MATLAB itself to separate R, G and B bytes and send them to separate registers in the PIC it would be most convenient.

8. After color detection a servo connected to RC2/CCP1 should do an action. All this 1 to 8 happens WHILE an electro-magnet connected to RC1 is high (holding the object) - so its one WHILE loop within the other when the communication occurs.

When the servo moves, the IR sensor goes high again because the object is moved from its place. But the electro-magnet remains high even while the servo is moving and it let goes of the object after the servo reaches a particular position.
------------------------

*
*
*I mainly need help on the communication part.

DISABLE and ENABLE requirements

As mentioned the PIC and MATLAB communication is disabled after point 6. It should only be enabled next when:

1. the electromagnet is switched on (after having been switched off) AND ..
2. when the the servo motor is in its original position AND ..
3. if the IR sensor has detected an object (i.e. low).


-------------------------------------------
The remaining C code, I think I can deal with less trouble (I will ask here for help if I have trouble). I found this MATLAB codes on the net. I would like members who know the matter to guide me:

http://www.mathworks.com/matlabcentral/answers/681-how-to-separate-rgb-values-of-an-image


A = imread('test3.jpg');
r = A:),:,1);
g = A:),:,2);
b = A:),:,3);


But, how do I enable a software means by which a snapshot should be taken and automatically be taken into the imread(); ? And how do I deal with the communication?


Thanks.

---------- Post added at 11:49 ---------- Previous post was at 11:46 ----------

Moderators, I posted this in Robotics and Automation by mistake. I should have in Microcontrollers, if you can shift the thread I would appreciate. Sorry for that :(
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top