CAN bus communication via BeagleboneBlack and Simulink - simulink

I have a running Simulink model communicating with a CAN bus. Messages are received, postprocessed and sent again. Now, I want to see this code running on a BeagleBone Black (BBB).
What is the simplest way to put a Simulink model with CAN Receive/Transmit blocks on the BeagleBone Black?
Do I need a CAN cape? What is the benefit of a CAN cape?
Is there a simple toolbox so that I do not need to write my own code on the BBB?
Thanks for your help!

Related

Signaling PLC with Raspberry Pi

I want to give signal via PLC to Raspberry Pi and when the raspberry pi gets that signal, it should run the python script and when the python script execute properly and cycle is completed, it should wait for the other signal from PLC to again run the same script and same cycle should go on.
Please provide some suggestions.
Via Network:
Depending on your PLC, you could use UDP or TCP, where a Python program on Raspberry listens and sends commands. Depending on the command received, different scripts ou actions could be executed. There are many Python examples for using this on the internet.
For the PLC it can be a little more complicated to find and it will depend on the model and manufacturer, I recommend that you check your supplier's documentation.
Discrete Inputs:
I don't recommend it, but if it's impossible to use a network, you could use discrete digital inputs (like buttons do) to trigger the scripts on the Raspberry, but it must have an interface with relays or optocouplers between the PLC and the Raspberry due to differences in types of electrical signals. In this mode, scripty in pyton keeps checking the status of a digital input and triggers the action when the status of the input changes.
Note:
Note that in both cases the program remains running (in an infinite loop), waiting for the command.
Additional care must be taken when using the Raspberry in an industrial environment due to possible interference by EMC. If using digital inputs, consider applying filters to the signal and shilded cables.

How do I write a simple bare-metal program?

Hypothetical here: Let's say you have a processor attached to some form of USB-storage and a motor. How would I write a simple bare-metal program to tell the motor to move for 10 seconds? I want to learn how to bare metal program, and having a program to look at and analyze would be wonderful. (Any language would be great)
1) you have to understand how the processor in question boots. there is the core processor itself then the non-volatile storage. for example a raspberry pi is a little unique in that there is something in logic (or an on chip rom?) that reads the sd card, boots up the gpu, then the gpu copies the arm program to ram and releases the arm into that ram. most microcontrollers have on board flash and ram and the flash is mapped into the address space that the processor boots from and/or there is a vendor supplied bootloader that boots the processor then calls your code.
2) you have to learn how to enable and initialize the peripherals you care to use. a timer perhaps if you want to count to 10 seconds.
3) write the application.
debugging is the trick, you can sometimes use a hardware debugger via jtag or sometimes use a rom monitor via gdb or some other program on some interface like uart. or one that almost always is available either a blinking led or a uart to send text or numbers out to see what is going on. and of course an oscilloscope, you can wiggle gpios or do other things and see them on the scope.
driving a motor is too generic you need to specifically know what kind of motor and how to drive it, likely zero chance you are driving it directly from the microcontroller, you might have something outside a transistor h bridge or something that isolates the microcontroller or you have a specific type of motor driver chip/circuit that you speak to either through discrete signals, or i2c or spi, or other to tell it to drive the motor, and then maybe some analog to deal with the high power or maybe that chip is a hybrid. so you have to know all that or at least you have to know the programming side of all that, what interface and/or what signals have to have state changes in what way to cause the motor to do something. it could be as simple as a pwm that you create that is amplified between you and the motor. pwm may involve first learning how to mess with one of the timers then either another peripheral or a subset of the timer to make a pwm signal out of it. a scope is really helpful here too or a logic analyzer, or if you have another microcontroller you can sample a gpio in faster than the signal being generated you can turn it into a logic analyzer.
start with finding a board, blink an led, figure out how to run a timer, accurately blink an led. figure out the clock rates you are really running at instead of guessing, figure out how to configure the uart, send some characters out that, now you have a debug interface a knowledge of what your timer reference clock speeds are and can now try to count to 10 seconds, and then get into the signals needed for the motor. expect to blow up a few boards, buy some spares.

Modelica modbus communication

I need to create a hardware-in-the-loop test setup. I will be using Modelica (Dymola) to do a real time simulation of a system. Dymola should send/receive data to/from some hardware and where the received data will be input to the model.
I am trying to communicate with Modbus over a serial connection. The hardware is a PLC-like device so this seems like the preferred method.
I do not have the hardware yet, so I am testing with an Arduino Uno. I have installed a Modbus-slave library from here on the Arduino, and tested it with it with an Modbus tester.
I cannot figure out how to communicate with Dymola. I have tried the Modelica_DeviceDrivers library and was able to send or receive (not both together) data from the arduino but not by the Modbus protocol. My question is if there is any modelica library for modbus communication or any other way to accomplish this from Dymola/modelica?
The free ModelPlug library will connect SystemModeler (and potentially Dymola too) to an Arduino board for I/O. You can download it here: http://www.wolfram.com/system-modeler/libraries/model-plug/
If you want to write your own drivers, you could go to the Resources\Include folder under Modleica_Device_Drivers library, there is a bunch of c header files, and they are very good examples of how to write your own driver. If you can write it in the way that it could be compatible with Modleica_Device_Drivers "package", then it will be quite easy to assemble/disassemble your data messages.
If you just want something quick, you can write a C function and reference it in Dymola.
Both methods may require when(sample(...)) clauses in order to sync your sim time with real time. But this means event generation, tho it is a time event, but for big models with a lot of states, it may slow down your simulation.
I would prefer to create several inputs and outputs around the model, then export the Dymola model as a C or FMU model, I'll write another communication program to control the data flow.

AES encryption using Verilog

So I took it upon myself to learn all about the FPGA this semester. To test my skills, I picked up a project to encrypt and decrypt files using a FPGA implementation of the age old AES. Now implementation of AES using Verilog has been done umpteen times and for my reference I used the code at http://opencores.org/project,systemcaes. What I wish to do is use the Verilog file handling functions to read a small file, use it as input to the encryption block on the FPGA, and save the encrypted file back on the computer. I am aware that this can be done on the testbench(though I have not attempted it, I am sure it can be done). But how do I do the same when I implement the code on the FPGA board? Is there a way to select the file to be encrypted/decrypted and pass it onto the board? Is it even possible?
Sorry if I come across as a noobie, its my first time in the world of FPGAs. Thanks in advance everyone!
You need to understand that the FPGA will only take a description of the hardware that you are going to build. It is not like a programming language.
So if you want to load data into a memory on the FPGA you need a way to move the data from you PC into the FPGA. The easiest way is to implement an UART on the FPGA so you can communicate with a serial port on your PC. Then you load data from some terminal program on your PC into the FPGA.
Then you can use the serial port to read the data back to your PC.
This of course require you to have implemented the hardware needed to read and write things to and from a memory in your FPGA.
It might also be that you can stream data through the FPGA. But then I think I would use two serial ports.
Verilog RTL does not have a concept of a file system, you would need the FPGA 'driver' to break the file down and send it over byte by byte or load it into a memory for the program on the FPGA to read.
I am not experienced with FPGAs, my under standing is that you synthesis the design and stream it into the FPGA. I thought that you might have still had some connectivity to the device where you were able to stream data to it. In the same way I think you can control the Arduino over USB.
How do you plan on getting the data back out of the FPGA? Do your tools allow you access to send and load data?

Matlab, Simulink, Making connection between multiple simulink models via Lan

There is a Simulink model composed of some subsystems, It is supposed to run each subsystem in a computer and all computers are connected to a LAN network.
There are interconnections between these subsystems and data shall be transferred between them so they should run synchronously and preferably real time.
But the computers have Windows operating system and so they do not have real time operating system.
I am searching to find a solution for this problem. what I have found up to now is that:
Simulink real time workshop can make executable code of simulink models but the code can be run real time just with real time processors and it doesn't seem that they can support connection between multiple computers.
XPC target is known but it just make connection between one host PC or hardware and one target PC and the target PC shall have real time OS. so it doesn't cover this problem.
There is a library for Matlab titled "Hardware Input / Output Library for Matlab / Simulink " by Werner.Zimmermann that have some good facilities such that it can make simulink to be run near real- time and it can make connection and send data via TCP/IP between two computers but it seems it can just make the connection between two computers running simulink.
It also have some constraints for OS and version of Matlab/Simulink and is not updated. So I'm not sure it would be enough.
After all of these, does anyone know a better way of handling this problem? I would appreciate any help on any of these topics to be useful or another ways to solve this problem.
Thanks in advance
see the following links (especially the first one):
http://www.mathworks.de/help/toolbox/instrument/brbv41k-1.html
http://www.mathworks.com/matlabcentral/fileexchange/4934
http://www.mathworks.com/matlabcentral/fileexchange/27290