Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Running user script in a microcontroller

Status
Not open for further replies.

hkBattousai

Member
I want to design a microcontroller system in which user can connect to its firmware via PC connection. There will be an IDE (integrated development environment) on the PC side which manages this connection. User will be able to write his own script in this IDE, and embed his own script to the embedded system by means of this IDE software.

The hardware can be for any purpose, I will not specify what a kind of MCU system I want to design. Actually I haven't decided yet, I'm only thinking on how to implement this scripting technology. Rather than, I want to focus on how to embed a script on this embedded system.

I have seen a commercial device which works with this principle. It was a servo-motor controller. User was able to load his own scripts into the system. An example script looks like this:
Code:
if ((position > 1000) || (position < 200))
    speed = 0;
if (data == -1) speed--; else if (data == 1) speed++;
In my example script I used C syntax, but the system had its own syntax.

This controller device was used over CAN communication. It was designed to be controlled by an application software (user's own software). User sends commands to this controller system by using his application software. He can set position, speed, acceleration of the servo-motor. He can also brake, turn on and off the servo-motor by his appliaction.

You may ask "If user can freely control the servo-motor directly by his application, why does he bother to a embed script the the device?".
There are two reasons to do such a thing. First, reducing the complexity of the application software and handling simple tasks in the controller (like limiting position and speed). Second reason, preventing any code errors during develepement period to cause devastating outcomes, like breaking some expensive components or injuring people.

Before starting such a big project, I need some advice and guidance on some matters. The greatest problem in my mind is how to put this script into the firmware.
Assume that, I compiled the script into some machine code of the microcontroller. How do I integrate this machine code to the one running in the microcontroller.
In PC develepment, you simply create DLL files containing a predefined function name, and put that DLL file into plugin directory of the application (Like the way Notepad++ plugins work). But it is not that simple in the world of embedded development. Is there any suggestions you can give about this?

I need idea, guidance, a starting point and maybe some online examples if there is any. Any reply will be appreciated greately.
 
Basically you're writing your own programming language, do it as either a compiler (in which case the created machine code is uploaded directly to the micro). Or as an Interpreter, like the BASIC STAMP - where the PC program compiles it to a PCode, and the program in the micro interprets that PCode.
 
The best way would be to compile it to machine code on the PC and use a bootloader to load it into the microcontroller.

Have a look at Flowcode, it turns your "script" into BoostC compatible code which is then compiled.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top