We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all,
I have a Tiva-C board that I configure with Keil. I want to perform a simple task - when my MATLAB runs a specific command, I want to send an "On" trigger (analogoutput 3.3V) to a NI PCI Board to start a camera device. Also, I am relativley new in programming in Keil. I have the following questions:
I have a small program that turns a connected LED on and off.
option 1 - Is it possible to write 2 function ledON/ledOFF that can be executed from MATLAB (without a main)? Something like -
// Make PA2 high void LED_On(void){ GPIO_PORTA_DATA_R |= 0x04; } // Make PA2 low void LED_Off(void){ GPIO_PORTA_DATA_R &= ~0x04; }
option 2 - should I load a program that runs in a loop and performs the task according to a "package" sent from MATLAB? Something like -
int main(void){ LED_Init(); // initialize PA2 and make it output while(1){ In = GPIO_PORTF_DATA_R&0x10; // read PF4 (read 'input' from matlab) ChangeLedState(In);' }
2) What is the most recommended way to interface a the Keil C-format files with MATLAB? What signal should it read, and how do I specify and connect to a specific GPIO port?
Any further wise suggestion is welcomed...
Noam
Let's think about other "controllable" devices around you, and consider what methods other people/companies might have chosen...
Isn't it quite common that devices that may be controlled from a PC is using RS232, USB or Ethernet to receive their commands - unless they are newer in which case they are nowadays mostly wireless?
Using a digital input pin to control a digital output pin feels quite strange - if you already have a digital signal you wouldn't need any microcontroller outside of the PC.
So how about using RS232? If your PC doesn't have any RS232 port, you can use a USB-to-serial adapter - there are cables with the conversion electronics integrated.
Great Idea, I was not familiar whit this connection type. I guess it is also much easier than with Tiva-C.
Thanks, Noam
As you seem to have good understanding I'll ask you the full question. The main goal is to create a super fast (1 ms time resolution) reliable communication line between 2 matlabs that run on 2 different computers. As I understand, you suggest to connect both computer via their input RS232 port? Concretely, should I get a male 2 male RS232 cable? Is there a better solution you can think of? Currently I am using a TCP/IP protocol which is not as fast I want (~300 ms).
Thanks again, Noam
You can't expect to get any protocol that gives you 1ms response times between two PC running a desktop OS, because the OS doesn't promise real-time performance.
So the protocol may sometimes manage a delay of less than 1ms - but may at other times give much, much, much longer delays.
This is why embedded devices so often uses an RTOS, where you can design around guaranteed worst-case response times of a high-priority task (assuming the developers knows their stuff). And why lots of PC interfaces contains hardware acceleration allowing the hardware to perform tasks without waiting for the OS involvement. And why lots of communications interfaces has significant buffers to reduce the amount of times the OS needs to be there to retrieve received data and fill the output buffers with new data to send. Buf big buffers obviously doesn't solve the OS-to-OS latency issue - they only improve the link utilization.
So in the end - you'll have to think again about your need of below 1ms latencies between two PC-class machines running standard OS.