hardware programming to control machine movement [closed] - hardware

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).

Related

About embedded firmware development [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In the past few days I found how important is RTOS layer on the top of the embedded hardware.
My question is :
Is there any bifurcation between device driver (written in C directly burned over the microcontroller)
And the Linux Device driver ?
This question is a little broad, but an answer, a little broad itself, can be given.
The broadness comes from the fact that "embedded hardware" is not a precise term. That hardware ranges from 4 bit microcontrollers, or 8 pins ones, up to big CPUs which have many points in common with typical processors used tipically on linux machines (desktop and servers). Linux itself can be tailored up to the point it does not resemble a normal operating system anymore.
Anyway, a few things, generally acceptable, can be the following. Linux is not, in its "plain" version, a real time operating system - with the term RTOS instead, the "real time" part is implied. So, this can be one bifurcation. But the most important thing, I think, is that embedded firmware tries to address the hardware and the task to be done without anything else added. Linux O.S. instead is general purpose - it means that it offers a lot of services and functionalities that, in many cases, are not needed and only give more cost, less performances, more complication.
Often, in a small or medium embedded system, there is not even a "driver": the hardware and the application talk directly to each other. Of course, when the hardware is (more or less) standard (like a USB port, a ethernet controller, a serial port), the programming framework can provide ready-to-use software that sometimes is called "driver" - but very often it is not a driver, but simply a library with a set of functions to initialize the device, and exchange data. The application uses those library routines to directly manage the device. The O.S. layer is not present or, if the programmer wants to use an RTOS, he must check that there are no problems.
A Linux driver is not targeted to the application, but to the kernel. And the application seldom talks to the driver - it uses instead a uniform language (tipically "file system idiom") to talk to the kernel, which in turns calls the driver on behalf of the application.
A simple example I know very well is a serial port. Under Linux you open a file (may be /dev/ttyS0), use some IOCTL and alike to set it up, and then start to read and write to the file. You don't even care that there is a driver in the middle, and the driver was written without knowledge of the application - the driver only interacts with the kernel.
In many embedded cases instead, you set up the serial port writing directly to the hardware registers; you then write two interrupt routines which read and write to the serial port, getting and putting data from/into ram buffers. The application reads and writes data directly to those buffers. Special events (or not so special ones) can be signaled directly from the interrupt handlers to the application. Sometimes I implement the serial protocol (checksum, packets, sequences) directly in the interrupt routine. It is faster, and simpler, and uses less resources. But clearly this piece of software is no more a "driver" in the common sense.
Hope this answer explains at least a part of the whole picture, which is very large.

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

How can I learn to build my own bootloader for an embedded system?

Does anyone know of a good learning resource for building your own bootloader for an embedded system? From reading various textbooks, I have a good overview of what a bootloader is supposed to do, and some textbooks include snippets of assembler to show how the bootloader should be built.
However, when I search for resources/tutorials that describe how to build a bootloader, everything I've found so far is either too advanced, (assuming a knowledge of certain preliminaries and are thus hard to follow), or, they are dealing with creating a bootloader for a pc or an emulator. Ideally I'm looking for a single resource/book, that covers preliminaries, and walks me through the process. I'm happy to purchase a particular chip, and relevant cables, if the tutorial/textbook requires that.
The term bootloader is quite broad, so does your quest have roots in a few dozen lines of code with a serial bootloader or are you interested in a linux type full blown operating system (uboot) that has gobs of features and drivers and stacks?
If you dont already know that answer or dont know what I am talking about you need to figure that out, I would start small...even if you desire the huge monster operating system solution, you should start with bare metal (which is what a bootloader is, a bare metal program) chip comes out of reset, your code runs first, blinks an led. Then control the rate of the blinking led, then if you have a push button read the push button and make it change the led (demonstrating input and output). Then find and use a timer to blink the led if you didnt already (use polling first please, interrupts later). Now you can do clock math and have an idea how the chips clock tree is so use that to get a uart up, tx only first, then rx/tx echo what your receive. THEN you are ready to talk about your first bootloader, which should involve some serial protocol (invent your own or use xmodem or something) that actually "boots" and then lets you "load" other programs after booting.
You can do all of this (well virtual leds in some other form) using simulators, and that may not be a bad idea since the hard part of bare metal is first off controlling the assembler compiler and linker to make a binary that actually boots up and runs. Then piles of sub $10 and sub $20 boards that you can learn to write a bootloader for (msp430 launchpads, the other launchpads, stm32f0 and f4 discovery boards, the raspberry pi, probably not the beagles avoid those for now, oh and a myriad of avr based boards, avoid x86 start with microcontrollers, arm, avr, msp430).

Microcontroller interfacing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I'm new to the world of embedded programming and I'm looking for information about interfacing with a microcontroller using I2C, USB, UART, CAN, etc. Does anybody know any good links, books, tutorials, about this subject? Since I´m a real newb on this subject I prefer if it is as basic as possible.
Since you are already a desktop developer, you can probably jump in somewhere in the middle. Download the user manual for the controller you plan to use. Get the example code from the manufacturers etc. sites for one of the simpler peripherals - UART is good.
Get a development board and an Eclipse/Crossworks/whatever development system that supports your board and get something to work - flash LED, UART echo or the like. Don't try to use a multitasker and interrupt driver first off - just poll the UART with as few lines of code as possible. Why - because just getting a development setup to compile, link, download and run one line of code is a considerable exercise in itself, without any complications from complex code. You have your development setup and hardware to debug first before you can effectively write/debug any code for the controller. Just getting 'blinky' code that merely flashes an on-board LED to work is a huge step forwards:)
Most controllers have dedicated groups/blogs, either on the uC manufacturers site or linked from it - join them.
If you want to get into this efficiently, get a board and try to get it to do something - there is no better way. Once you can get a LED to flash or a UART to issue a string of chars, you're off to the races:)
Developing simple 'blinky' or UART-polling functions are not wasted - you can continue to use them later on when you have more complex code. Blinking a LED, (with the delay-loop replaced by an OS sleep), is such a good indicator that the code is sorta running that I've always kept it in on delivered systems. The UART poll is useful too - it will run without any interrupts and so you can call it from the data/prefetch/whatever abort vectors to issue the many 'CRITICAL ERROR - SYSTEM HALTED' messages that you will get during ongoing development:)
Wikipedia really is as good a place to start as any to learn the basics surrounding each of these mechanisms.
Once you've got a grasp, I'd recommend looking at an actual datasheet and user's guide for a microcontroller that has some of these features. For example, this 16-bit PIC has a dedicated UART, I2C and SPI bus. Looking at the relevant sections of the documentation, armed with your new knowledge of the underlying principles, you'll start to see how to design a system that uses them.
The next step would be to buy a development board for such a device and then, using example code (of which there is tons), code yourself up some datalinks. Incidentally, a UART is certainly the easiest to test, since all PCs can transmit using the RS-232 protocol from a terminal, so in this case you can code a loopback to transmit and receive characters with relative ease. With I2C and SPI however, I think you would need to buy a dedicated host dongle to allow you to transmit using the protocols, although I think Windows 8 might be introducing native support (but don't quote me on that).
I haven't implemented a datalink using CAN, so I can't comment specifically, although I just did a quick Google search and there's a PIC family that supports it, so I'm sure you could follow a similar approach. As for USB, I consider it a bit of a black art, so I'll leave someone else to answer that one - although I do know you can get a USB software stack for PICs, so again, a similar approach could probably be followed.
On a final note, I've only mentioned PICs as an example microcontroller. If you're not familiar with microcontrollers in general, you'll soon realise that all the major microcontroller families from companies like Microchip, TI and Atmel generally follow the same design, so I would have a browse and pick the family who's documentation you're most comfortable with (or least uncomfortable with, as suggested by Martin James!).
For the most part the data sheet or reference manual for the microcontroller you intend to use is what you need. Each vendor will implement these interfaces in different ways, so that is your only definitive source for low-level programming information.
I2C and UART are relatively simple with no standard higher-level protocol stack; that would be defined by you or the device you might be connection to. Your microcontroller vendor will almost ceratainly have example code and/or application notes.
CAN is more complex, and typically CAN networks use a higher-level application protocol of which there are several for different application domains such as CANopen, NMEA2000, DeviceNet, IEC J1939 and more. Most often a third-party library is the most cost effective method of implementing an application protocol stack, but if the network comprises of only devices you are implementing, then that complexity may not be necessary. Again your microcontroller vendor is likely to have examples.
USB is very strongly defined by the USB Implementers Forum, and protocol stacks are non-trivial. Most microcontroller vendors that have on-chip USB interfaces will provide sample code and application notes for at least device-class USB. USB Host stacks are more complex, and again the use of a third-party library (which are relatively expensive) is the quickest way to market. Fees you would otherwise be obliged to pay the USB IF may make writing your own host stack no less expensive. Even for a USB Device interface you will strictly need a USB Vendor ID at $2000 from USB IF. Some microcontroller and library vendors will allow you to use their Vendor ID for a defined subset of Product IDs at little or no cost, but you would probably have to be a significant customer in terms of volumes. For internal experimentation, you can probably get away without an official VID, but such a product could not be released commercially.

I want to make a program with embedded development board [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am studying about programming, so I want to make some programs.
Actuall, nowadays I'm studying embedded with embedded development board.
so, I want to make embedded program....
but...... I have no ideas...... what program I can make.
so could you guys recommend for me????
The program you write will depend upon what hardware you have or what skills and equipment you have to build your hardware.
If you have no hardware (or electronics skills), then buy an off-the-shelf development board, and then the program will depend on the features available on the board. The simplest will have no more than a serial or USB port and some I/O pins direct to the microcontroller's GPIO and peripheral device IO; you will need to attach additional hardware to this. More expensive boards may include fast 32bit processors, displays, Ethernet, memory card interfaces, large external RAM/Flash memories, WiFi, buttons, switches, LED's etc.
At the very minimum if you have never brought an embedded system up before, you should do exactly what you might do on a desktop system when learning to program it; that is write "hello world". In this case teh text should be emitted from the serial port, and displayed in a terminal emulator (such as TeraTerm or if you must, HyperTerminal). This will confirm that you have the development tool-chain and work-flow working and can build an load the binary to the board. It will also verify that you have basic serial host communications working which will be beneficial for debugging, especially if you do not have dedicated debug hardware such as a JTAG emulator or ICE.
You may find that your development tool suite, or the microcontroller or board vendor's website includes demonstration examples for your hardware which will include basic driver code. No doubt there will be a simple serial I/O demonstration that will suit the "hello, world" test. It may perform direct serial output, or it may be more sophisticated and provide library retargetting code such that standard I/O library calls such as printf() and getchar() will work over the serial port.
Once you have got the basics sorted, you are then perhaps ready to decide what to build. If your board has a dot-matrix graphical display (even a very small one), and a few switches or a potentiometer, then a simple arcade game such as breakout, defender, invaders, or even pong would be possible and give instant gratification!
One of the most rewarding things you can do with an embedded system is make stuff move. Motor control and robotics applications are most rewarding and have important real-time requirements that will develop skills that are not generally utilised on a desktop application. For such applications you will need additional hardware to interface to high current devices such as motors, such as a simple H-Bridge controller. You can purchase such hardware from a number of robotics kit suppliers, or you can build your own if you have the skills and equipment necessary. I suggest starting with a simple "big-trak" style mobile vehicle (Meccano or Lego-Technic can be used if you have limited mechanical skills), and then perhaps add sensors such as bump-switches, light-detection, line follower, ultra-sonic, odometry etc.
When your applications ger more complex, you will benefit from learning about an deploying a simple RTOS or real-time scheduling kernel.
Clock program. With a timezone converter.
You could look at programming an Arduino ( http://www.arduino.cc ) or perhaps a MAKE controller of some sort ( http://www.makethings.com ). It really depends on what you want to do! Enjoy!
I think this s3c6410 board may fit what you need www.developmentboard.net called tenbyten6410.I just bought it few days ago, now its working perfect in our project. I hope it will work in your project, as good as, in mine .