Author Topic: Simulink to PIC16F887  (Read 4042 times)

0 Members and 1 Guest are viewing this topic.

Offline twinsratioTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Simulink to PIC16F887
« on: May 04, 2011, 10:07:11 AM »
Hi there,

Actually I'm doing a project of DC Motor Speed Controller Using Fuzzy Logic. At this stage I've programmed the speed control(PWM) using 16F887 MCU. And on the other hand, I have also developed a set of fuzzy rule in matlab simulink. My problem is I do not know how to link my hardware (MCU and Motor) with the fuzzy logic that I have in matlab. As I know, I will be using RS232 connect/link matlab and MCU so that they can transmit and receive data from each other.

In matlab simulink, someone told me that I have to use the block serial send and serial receive under the instrument control toolbox, however I do not know to use and what coding should I program so it can link with my hardware and when I drive the motor I can observe the sampling of the data with the reference.

As my motor is attached with quadrature encoder, thus I can get the pulse from the encoder and convert it to rpm. That's mean it is a closed loop system. I do not know how to programme both matlab and PIC so that when I manipulate the fuzzy rules I can also observe how the motor driving corresponding to the fuzzy rule that I set.

Thank you in advance.


Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Simulink to PIC16F887
« Reply #1 on: May 04, 2011, 10:32:03 AM »
For the PIC look up the Microchip app note AN774 to learn how to use the PIC's UART for serial communication.
It will also need a logic level to RS232 level IC (MAX232) to connect the PIC to a PC Comm port.

I know nothing about MATLAB except that it can interface to a comm port. Try a web search for MATLAB Serial comm.

Offline happy_hippo

  • Jr. Member
  • **
  • Posts: 45
  • Helpful? 0
    • Read Stuff Here
Re: Simulink to PIC16F887
« Reply #2 on: May 23, 2011, 11:57:07 AM »
Hi, I've never used Simulink , but I used Matlab to control stepper drives (or Euro 205 motion controller, which is programmable in BASIC) via rs-232 protocol. First I checked that HyperTerminal can send and receive commands to the controller. Then in matlab:

- create a com serial object:
Code: [Select]
s = serial('COM1');
-set object parameters (like in HyperTerminal properties):
Code: [Select]
set(s, 'BaudRate', 9600, 'StopBits', 2);
set(s, 'Terminator', 'CR/LF', 'Parity', 'Even');
set(s, 'FlowControl', 'software');
set(s, 'Databits', 7);

-initialize serial port:
Code: [Select]
fopen(s);
-send commands to the controller by using fprintf (you need your controller commands for this), e.g.:
Code: [Select]
fprintf(s, 'BASE(0,1,2)');
fprintf(s, 'UNITS = 6410.25641');
fprintf(s, 'move(20)')

-I noticed that for my controller (or maybe matlab in general, I don't know), I could only send about 120 commands consequently and then I had to disconnect and reconnect to the serial port (but it takes fractions of seconds)

-to disconnect from the serial object:
Code: [Select]
fclose(s);
I hope that helps.

Happy Hippo

??? -> :D

 


data_list