FPGA input into Simulink - usb

I have a DE2i-150 board. I currently have a Simulink model that introduces a sinusoidal input into an external control system. Rather than using the Simulink library for my input how would I use the board instead. I.E. I'd like to output data from the FPGA board which acts as the sinusoidal generator. The board can output data through USB,data, or serial ports. To clarify, the sinusoidal input I'm talking about is merely a Simulink block. Therefore, theoretically I think I should be able to examine the C program that Simulink creates and know which data to output from my board. Would I need to have Quartus running at the same time? Any ideas or advice would be greatly appreciated.

I didn't quite understand what you want to do exactly, but here are some ideas that you could start looking up:
writing your own S-Functions to call an external API that accesses your FPGA and generating C with Simulink Coder or Embedded Coder
writing Custom Storage Classes to call an external API and generating C with Embedded Coder
converting your model to fixed-point and generating VHDL with HDL Coder.

Related

How can I write raw data on SD card without filesystem by using DSP?

I'm new in embedded electronic/programming but I have a project. For this project, I want to write raw data provided by sensor in 512b buffers on a SD card (SPI mode) with no filesystem.
I'm trying to do it by using the low level functions of the FATFS library. I've heard that I have to create my own format and rewrite functions to do it, but I'm lost in all those lines code... I suppose that I have first to initialize SD by using a command sequence (CMD0, CMD8, CMD55, ACMD41...).
I'm not sure for the next steps, if I have to open a file with the fopen function and then use the fwrite function...
If somebody can explain me how it work for a non filesystem SD card and guide me in the steps to follow I would be very grateful.
Keep in mind that cards with a memory capacity > 2Tb are not supported in SPI mode
(Physical Layer Simplified Specification.
If you don't want to use a file system, then fopen, and fwrite are irrelevant. You simply use the the low-level block driver. If you are referring to http://www.elm-chan.org/fsw/ff/00index_e.html, then the API subset you need is :
disk_status - Get device status
disk_initialize - Initialize device
disk_read - Read data
disk_write - Write data
disk_ioctl - Control device dependent functions
However, since you then have to manage the blocks somehow so you know which blocks are available and where to write next (like one large file), you will essentially be writing your own filesystem (albeit a very simple and limited one). So it begs the question of why you would not just use an existing filesystem?
There are many reasons for not using FAT in an embedded system but few of them will be resolved by implementing your own "raw" filesystem without you doing a lot of work reinventing the filesystem! Consider something more robust and designed for resource constrained embedded systems with potentially unreliable power source, such as littlefs.

How to send data to target through Trace32 debugger?

I need a way to send some data to the ucontroller through Trace32. I heard that this is possible some way, but I have no idea where to start.
What I am actually trying to do is run a piece of code on a Aurix TC297 ucontroller to do some measurements (runtime, RAM, etc.). This piece of code is actually a Kalman filter that needs as input a vector of structs that I have too send from the computer through Trace32. Please help !
"A way to send some data to the ucontroller through Trace32" is a little bit vague. There are various possibilities depending on what your actually try to achieve and might also depend on the used CPU family and target OS. Anyhow one of the following might work:
Simply writing some raw data to the target memory can be achieved with the Data.Set command.
To transfer a big amount of data (or even a whole application) from a file to the target memory the Data.LOAD commands might be the right choice. E.g. Data.LOAD.Binary command for a raw binary file.
To set variables in your application or even initiate C-style data arrays use the Var.Set command.
To write data to NOR flash or onchip flash memory you'll need the FLASH.AUTO command in addition to the previously mentioned commands (after declaring the flash memory to TRACE32).
To write data to a NAND, SPI or other serial flash memory you probably should use the FLASHFILE.Set command (after initialization of the FLASHFILE programming system).
To transfer data from TRACE32 to your target while the CPU is running you might have to configure correctly SYStem.MemAccess and use the memory access class prefix "E". E.g. Data.Set E:<addr> <data> or Var.Set %E <expression>.
You can use FDX for a bidirectional data transfer between debugger and a running target application.
To enable the target application to open and read files from the computer running TRACE32, you have to compile your application with suitable semihosting code and initiate semihosting in TRACE32 with TERM.GATE command.

Why should one learn register level programing for embedded systems, when options like Arduino IDE ,etc are available?

I have done projects using Arduino IDE.I have seen that many projects can be easily implemented using the IDE.Then, why should one learn register level programing? How important is it?
Can you do EVERYTHING with the Arduino library? If your project would need tight timing (for example to control a huge industrial apparatus), at the level of microsecond fractions, would Arduino still be a good choice? How about medical devices? How about performance - would you be able to design a BLDC controller using Vector Control in Arduino? How about battery life - would you be able to design a device that would run with a single CR2032 cell for a few years using Arduino? How about doing a network router? Does Arduino support threads?
Your question is like one of these:
who needs x-bit microcontrollers when we have y-bit microcontrollers at the same price?
who needs x programming language when we have y programming language?
who needs analog solutions when we have digital solutions?
who needs microcontrollers when we have microprocessors?
...
To be honest, personally (I write firmware for embedded devices),I see Arduino as a toy, nothing more.
Learning register level programming will help you learning how to read a datasheet, and also understanding how stuff works. It will give you more flexibility after you get the hang of it, plus you can optimize your code and write your own libraries.
By knowing how to read a datasheet it will be easier for you to develop device drivers and process algorithms.
What would you do if you cannot find an Arduino library for a certain sensor? If you were using register level programming, you could easily write your driver, by already knowing how to interpret the technical files ;).
Try it out, you will forget Arduino in the first weeks!
Best regards,
Alex Tofan

hardware programming to control machine movement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how does a computer program control a mechanical movement, what is the bridge between the object code and a certain machine part.
Let us say I have a certain paint sprayer which is directed, and I wanted that to move circularly either
1. Start at the circumference of a certain radius circle and paint circularly and stop when it reaches to the center of the circle or
2. start at the center of the circle and run around until it reaches a certain radius.
and if I represent my sprayer as noselPaint and how that progamatic noselPaint construct is linked to actual spraying tip to control its movement in a uniform manner.
Your question is too broad, but I'll try to highlight main steps for task of this kind.
Any mechanical hardware that controlled by the PC programs contains the next main parts:
PC program
Motor controller board (with the heart is microcontroller e.g. AVR, STM32 or any other)
Power drivers (provide high electric current for mechanical part motors)
Motors (usually servo-motor)
PC program read the control file and then send data to the driver motor controller board (e.g. most common case nowadays by mean of USB). After that microcontroller process data and generate signal to the motors, that rotate the shaft to appropriate angle. In processing data stage includes storing received data to the internal controller memory and recalculation (if required) from angle data to the voltage levels or to required "time". Then it pass to motors. Another words servo-motor can't rotate to an angle 63 degree (it not understand what mean "63" digit) but it can get as I wrote above voltage or PWM (it depends on which kind of the servo-motor microcontroller works).
PC program can be written on different programming language C, C++, C#, Python or others. But to negotiate with the controller board driver required. Other way is using libusb library that has bindings for different language.
Microcontroller also has program that writes to its flash-memory (this program named firmware). This program write with assembler or C language (for more complicated firmwares).
Implementation of such kind tasks required knowledge not only in PC programming but also electric and electronic circuits design, OS driver programming, standard hardware interfaces implementation. And also complicate task is design construction of your moving parts.
To getting started with your question I can recommend your to get a evaluation microcontroller board (e.g. STM32F103VB contained hardware USB interface or AVR ATMega16 or ATMega8 simpler microcontroller but has no USB interface). And as moving part is HS645mg servo-motor.
UPDATE:
Simple evaluation board for STM32 microcontroller, required only one board the heart of motors controller bridge.
STM32 Programmer, required to flash firmware into the microcontroller memory (only one required for development)
Servo-motor, is the moving part (number of motors depend on your task and device degrees of freedom, i.e. joints)
Simple and easy to use power circuit parts, required to provider high current for servo-motors.
All of these parts can be bought on ebay, but usually more swiftly approach is to look up electronic store in your region (of course not a consumer electronics shop).
Working with microcontroller (MC) is quite simple:
MC tutorial
MC video tutorial
Also I think you can find a lot of similar tutorial by Googling "STM32 getting started". Program for STM32 microcontroller written in C language via e.g. Coocox IDE (it is based on Eclipse IDE) and compiled by special compiler ARM GNU toolchain.
As for PC program read the control file I mean that:
Control file is simple binary or text file with data represented in format that easy to read in program, for example it can be sequence of coordinate where your paint sprayer should be moved at or something like that.
PC program is the common program that written in any programming language your familiar. Most of language are suitable for this task. The main objective of program is read control file (that was described above) and send data to controller board by mean of USB.
Sending data to MC isn't much differ from working standard library. The simplest way to send data via USB is using libusb library. But as for setup USB on microcontroller is more complicated task however there are a lot of detailed manual on STM32 MC at the official web-site (e.g. STM32F103xx).

Bit packing blocks in Simulink?

Could anyone please explain to me what the bit packing blocks in Simulink do? I am currently learning programming, Simulink and control theory so I am not very proficient. I tried using the help windows in MATLAB and also googling but I haven't found anything that explains it well.
Based on the online researching, bit packing is used to condense data packets before they are sent to another block? This way, the program runs faster?
Also, in Simulink, what is the "Bit patterns:" box used for? For example, if I type {[0:7]} what would that mean?
Edit: Where should I go to learn more about this? Are there any good documents online?
Byte packing and unpacking is used mostly for communications between a xPC Target and another device, over Ethernet for example. If bytes are coming in, they can be condensed into other data types such as singles or doubles. Conversely, if you are sending out doubles or singles, often you need to separate them into bytes first.