'Production Quality' AVR BASIC Interpreter?

Go To Last Post
45 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anyone come across a production quality AVR self-hosted BASIC interpreter? And one that is extensible (ie easy to add new keywords/built-in functions/pre-defined variables/etc)?

 

I've been asked how easy it would be to add user-defined functionality to an industrial controller unit. The unit is similar to an industrial PLC, it has digital, and analogue, inputs and outputs. The ability is desired for ended users to be able to write instructions like...

 

"IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON"

 

I've found several hobby-level projects (and I don't mean that as an insult) but I'd happily pay money (or in the end my client would) for a commercial product which comes with some back-up.

 

In my mind I'm looking for something like the original Microsoft 8k or 12k 8-bit interpreter, but written in C and  not assembler. And with commercial licence terms.

 

I can find plenty of 'tiny-basic' clones, lots of abandonware and lots written in assembly. But nothing fit for a commercial product.

 

The only code running on the PC/Mac/Linux box would, in an ideal world, be a VT100 terminal emulator.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Silly question but does it have to be BASIC? Forth was invented for almost exactly this purpose and if you can get over the RPN it's a possibly "better" solution as it's designed to be extensible from the start and it's well suited for messing with SFRs and stuff.

 

(my 3rd year dissertation at Uni was about various implementations of Forth - I implemented it on an RT/11 and a 6809 - the actual design of threaded interpreted languages is very clever indeed. I think the "core" on the 6809 was something like 4..5 opcodes and on the PDP/11 it was one opcode!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you looked at things like Scratch? This generates a bytecode that is simple to implement. It is a bit like Basic Stamp - the user interface is on a PC and downloads the ‘compiled’ bytecode for execution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But bytecode implies "compilation" doesn't it? Is it actually "interactive" ?

 

(actually now I re-read Brian's post maybe it isn't interactivity he is looking for? I just took it that "IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON" was something you might type "live" with an immediate result but I'm probably tainted by Forth!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
maybe it isn't interactivity he is looking for?

But

Brian Fairchild wrote:
The only code running on the PC/Mac/Linux box would, in an ideal world, be a VT100 terminal emulator.

So it looks like he wants to avoid any specific "tools" being required on the "host" ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So it "lives" in the AVR but that still raises the question of compiler or interactive interpreter. I guess the comparison to MS Basic (or in my experience: Locomotive BASIC, Spectrum Basic, Z80 Basic) does suggest an interpreter rather than a compiler.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
similar to an industrial PLC

Don't they typically use Ladder Logic ?

 

Looks like implementations exist; eg http://cq.cx/ladder.pl - but I don't know about meeting your other criteria ...

 

It has to be for an AVR - does it?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Basic, hmmm,  I'm sure you can find a few old apple ]['s or radio shack coco or commadore 64/128 on ebay some where!  smiley

ahh the good ol days..... 

 

 

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not BASIC, and not commercial, but there's Bitlash:

http://bitlash.net/

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm...

Basic:

IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON

 

Forth:

digi-input4 HIGH? ana_input7 100 > AND IF digi-output3 ON THEN

 

A little formatting:

 

digi-input4 HIGH? ana_input7 100 > AND 

IF 

  digi-output3 ON

THEN

 

I don't know...

Depends on the end users type... If they are profesionals, no problem I suppose. A very simple forth is easy to learn.

 

A big problem with forth in my experience is not the RPN but the fragility of the system. You can make it crash very easy :(

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting project.

 

If the program runs on the micro, what stores the program so the user can re-run it without retyping it in?

 

You likely are aware of both Bascom and ZBasic, both of which have commercial license options.

(And both of which have a compiled version, while ZBasic original Z-chips ran an on chip interpreter, IIRC.)

 

I'm not sure why the language needs to be extensible?

I'd have thought that the core instructions would be sufficient for handling simple I/O logic as you mentioned above.

As new HLL instructions are added to Basic it is usually to simplify something like an interface to a WiFi chip, or a digital LED, etc.

Not likely a requirement for your project.

 

I'd have thought your approach might be to define a list of I/O pins, and type, (digital, analog, etc.).

Define a few PWM channels, and some standard modules, (LEDs, LCD, input switches, etc.).

 

You then define a list of instructions, (an example of which you gave above).

The User is merely filling in the blanks on the standard equations available.

 

The micro is actually running its own program, (written in any language), to parse the "program", (list of instructions), provided by the end user, and perform their action.

 

The program running on the micro is essentially a big parser, except you know ahead of time the list of options for the commands, so it is much easier than parsing random language or math equations.

 

You would have a menu / "IDE" for the console, running from the micro, which included "Save" to a microSD card, EEPROM, or whatever.

 

So in essence, you would be writing your own language I guess, with some similarities to the Arduino setup.

 

Also some similarities to a CNC machine interface.

 

JC

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rammon wrote:
A big problem with forth ... You can make it crash very easy 

But, then, people say the same about 'C' ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think a large part of any interpreter is the tokenization.  It seems that it would make more sense if that part were on the PC end of things (though I do see the benefit of having it on the AVR side).  If on the AVR side you would at least benefit from having very rigid and restricted variable and keyword naming conventions, nesting depth, allowed operators, etc. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Would this be of any use?  ...of course it looks like abandonware....

https://www.seanet.com/~karllunt/klbasic_main.html

 

This one actually generates composite video...remember those days?

https://hackaday.io/project/2428-single-chip-avr-basic-computer-v03

 

This seems maintained on sourceforge.... works through different i/o devices, using vt100 commands;

https://sourceforge.net/projects/terminal-basic/

 

This looked quite interesting

https://www.instructables.com/id/Arduino-Basic-PC-With-VGA-Output/

 

Of course, none of these are commercial offerings :(

 

Here is something that is extremely well documented, but alas is not Basic

http://bitlash.net/bitlash-users-guide.pdf

 

Perhaps you've already run into these and rejected them...

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

"I can find plenty of 'tiny-basic' clones, lots of abandonware and lots written in assembly. But nothing fit for a commercial product."

 

I humbly suggest that take these half-baked and nearly-useless code items and turn them into your own commercial product.

 

 

"IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON"

 

I suggest that result of rewriting and rearranging of the above code clones and junkware  be limited to a tiny number of keywords and variables.  In the line above, (which, if interpreted, would not use any resources that are not in the line of code) there are two GPIO boolean variables, one (I assume) 16-bit variable, five keywords  (if,=,and,>,then), and two pre-defined logic states(HIGH, ON).   I assume that boolean variables are getting their values from sensors.  The integer value comes from either an serial terminal input (the input value in ASCII representation), or, from an analog-to-digital convertor.  

  Try the simplest possible approach by having no more than, say, eight keywords, 3 or 4 boolean variables, and 1 or 2 integer variables.  Input a text line and parse it into keywords and variables, then use the techniques described in the junkware.

 

I,too, once studied FORTH.  With all respect, FORTH is a disaster of programming language.   It is like Esperanto: a perfectly designed language that too much of a pain in the poot to be taken seriously and used by anyone.  Except for the (very few) people who could learn it.   In the early 1980s, FORTH was the only advanced language available for one of the new "home computers"; the Commodore VIC-20.  And only available on ROM cartridge.  And only where game cartridges were sold.  Which was in toy stores.  So, to get your advanced computer language, you had to go to Toys'R'Us and browse through all the dolls and plastic children's toys to find your advanced computer operating system.   Which could be hard to find in the store.  And the sales clerk won't be much help when you asked if they carried FORTH, an advanced computer operating system.  I showed my first FORTH program to the other programming students in the community college engineering school that I went to then, and they all agreed that it was the product of a sick mind.

Last Edited: Thu. Sep 6, 2018 - 06:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Someone for Germany?? was selling a BASIC interpreter for AVR and used to post here, I looked on my current computer and can't find it but it may be on my old computer.

 

From memory I tried it out on a Mega644p or maybe even something with a larger EEPROM where the programs where stored.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
... or interactive interpreter.

Logo

uLisp®

Implementation

http://www.ulisp.com/show?1AWG

...

 

Acknowledgements

...

I am also grateful to the user clawson on AVR Freaks who showed me how to design a procedure name lookup table in program memory.

 

...

uLisp is current, the megaAVR instances hold up well against MSP430TM in its benchmarks, and it's MIT license.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can find plenty of 'tiny-basic' clones, lots of abandonware and lots written in assembly. But nothing fit for a commercial product.

Exactly what would make such a thing "fit for a commercial product"?

  1. Someone to yell at when things go wrong.
  2. Someone who wrote documentation on use and extension?
  3. The adrenaline rush caused by the constant fear that your vendor will go belly-up and leave you stranded with no source, no support, and a product you still need to support?

 

Forth was invented for almost exactly this purpose

As long as I'm being snarky, I'll bite.  Is there an AVR Forth implementation "fit for a commercial product"?

I'll point out that it's relatively easy to implement a tiny forth-like language useful for "extensions" without going to a full-blown implementation.

 

Are there any vendors that offer ANY sort of "extensible interpreter" for inclusion in larger projects on custom hardware?  (Gee, the "Vendors" section of AVR-Freaks has gotten pretty useless!)

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If using BASIC is not an absolute requirement, then looking at Lua may be worthwhile.

I've not used it myself but know that it's added quite often to 3D games, for example,

as an extension language.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lua is a delightful language but WAY too big for AVR. Needs garbage collection and a fair bit of memory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the BASIC project but it is written in assembler.

 

;# chipbasic-M32 v0.93                                #
;# single chip basic computer with ATmega32                    #
;# copyright (c) 2006/2007 Joerg Wolfram (joerg at jcwolfram dot de)            #

That was 10 years ago!! I must have had lots of fun because time has flown.

 

Joerg was very helpful then sorting out a few things, don't know if there has been any more progress.

 

The latest post may have been this one https://www.avrfreaks.net/forum/...

 

EDIT seems to be still going with V1.51 for Mega644 as of 26.3.2017

http://www.jcwolfram.de/download...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Fri. Sep 7, 2018 - 05:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Speaking of PLC like programs, there is also the IL (instruction list) which is kinda assembler.

I implemented once a simple IL language for one of my devices. The device was (is) an weighing indicator and had some i/o (optocoupled digital inputs, some relays).

The problem was that every application needed some different "program" -- none of the real usage was just a simple "indicator".

So, we implemented an application language/interpreter, IL type (I was at that time quite used with IL, I was programming PLCs and found that the IL was much "faster" to my programming skills...)

Well, the indicator was based on Atmega8535. IL was stored on byte code in internal eeprom, and also executed "in place", in eeprom.

This was quite tight in the first place for an 8K flash mcu, and we switched to pin compatible atmega16 soon.

 

Here is some IL:

 

' simple plc test program

 

LD IN1

AND IN2

ST OUT1 'OUT1 = IN1 AND IN2

' OUT8 = (IN3 AND IN4) OR (IN5 AND IN6)

LD IN3

AND IN4 ' IN3 & IN4

ST B1000 ' use a temporary variable (B1000) to store IN3 & IN4 

LD IN5

AND IN6 'IN5 & IN6

OR B1000

ST OUT8

LD KEY36  SET.T OUT4 ' KEY36 turns OUT4 on

LD KEY35  CLR.T OUT4 ' KEY35 turns OUT4 off

 

' W100 = a simple counter

LD KEY1 ' KEY1 clears W100

LDW.T 0

STW.T W100

LD KEY2 ' KEY2 increments W100

LDW.T W100

ADD.T 1

STW.T W100

' here we implement an alternative way of incrementing the W100,

' by IN5 rising edge. We use a temporary bit, B100

LD IN5

CLR.F B100 ' if IN5=0 then B100=0

ANDN B100 ' if (IN5=1 & B100=0)

ST.T B100 '   then B100=1 

LDW.T W100 ADD.T 1 STW.T W100 ' W100++

 

LD KEY3 ' KEY3 decrements W100

LDW.T W100 SUB.T 1 STW.T W100 ' example of multiple instructions on a line

 

' if W100 > 5 OUT2=on else OUT2=off

' this is just to see the W100 counter is working

LDW W100  

GT 5  ' W100 > 5 ?

 

ST OUT2

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forgot to say, the compiler was on PC.

The device had only a loader on the serial port (kind of bootloader) to get the byte code and store it in the eeprom.

But the compiler was very simple, a command line .exe (a plain C application (mingw))

We planned to put that C application inside the microcontroller but never did that...

There was two ways of thinking:

- some thought that having a better PC/host program was the best, a program having some debug facilities too

- some thought that having the compiler inside the device was best. Here there was a problem: was the text source needed to be stored too inside the device or not? Having the text at hand was nice if we decide to develop a embedded debugger too, but the real hardware didn't support that (we didn't have an external eeprom/serial flash).

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Your example:

"IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON"

looks a bit like the Structured Text Language that is one of the 5 methods used to program PLCs.

 

As such; http://www.openplcproject.com may be of interest as they indicate it can run on Arduino.

This also: http://www.plcacademy.com/structured-text-tutorial looks a good read.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Exactly what would make such a thing "fit for a commercial product"?

Ah.  If I might answer my own question, in perhaps a interesting way:

 

A "suitable commercial SW product" essentially "crowd-sources" the development and support costs of software.  Instead of paying big bucks (internally or otherwise) to someone to develop the SW, and more big (and unpredictable) bucks for a consultant to fix anything that goes wrong, you want to have a predictable and much lower cost (license fees, or a "subscription") to someone who is hopefully collecting those fees from a number of customers, enough to do "continuous" fixes and development.  Sort of the RMS model of Open Source, without needing to be "Open."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
Sort of the RMS model of Open Source, without needing to be "Open."
RMS - Richard Matthew Stallman

There are SMB and somewhat large operators that are successful with dual-licensing (GPL, commercial)

GPL for a computer language run-time adds to the set of operators (commercial + otherwise) which increases the probability of defect discovery.

Commercial operators receive value-added by a number of means (static analysis, dynamic analysis, private test cases, tools, customization, etc)

FOSS that's non-GPL likely has dual licensing, or, a FOSS creator does VAR.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
... (license fees, or a "subscription") ...
A per device instance fee is how Zerynth is receiving revenue for Python on some MCU (arm Cortex-M, ESP32, ESP8266) (SAM3X8, SAM D21, SAM G55, SAM L21)

Those MCU families are also in MicroPython (MIT license) if one wants to DIY.

 

https://www.mouser.com/new/zerynth/zerynth-middleware-freertos/

https://www.zerynth.com/get-started/#licensing

https://www.zerynth.com/zerynth-supported-devices/

https://micropython.org/

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Last winter I ported the old SOL 20 extended cassette basic over to a Mega328.  I think I had about 140 bytes left over for a program.  Of course this was written in ASM  and would qualify as abandon ware.   Surprisingly it worked quite well.  If one wanted to write 10 line programs.  Eventually I was going to make a SD card file system to emulate the tape storage.    I have learned that such things do not really work well in a Harvard system with limited read write SRAM.   I have two different pipe organ control systems I play around with.  One uses a lot of memory buffers in linked lists.  It was designed for DEC architecture (PDP8 type stuff.)  This has evolved to use a full blown computer UDP packets and various modern object frameworks for string handling and such.

 

The pipe organ controller was based on more of a PLC type structure where each rank of 61 pipes gets it's own processor.   The latter system uses RS485 on simple twisted pair.  The sub modules run a sort of interpreted protocol based on a series of 'function' tokens which are processed at a much slower speed than the main frame scanning.  I have not looked in depth at how modern PLCs work.  I suspect that such are quite similar.  That it would be practical, to define a pipe organ control with ladder logic.  The electro-pneumatic switch stacks are literally ladders.   With feedback where a switch in the stack can open a valve which causes the air motor to release self same switch. 

 

 

With any interpreted language, such as basic or pascal, there is usually some sort of  engine that takes the 'B' or 'P' codes so that only the back end needs to be re-written.  Back in the early 1980s I wrote a basic interpreter in PL/1.  Which I think was a language ahead of it's time.  These days I tend to do everything in postscript, AVR assembly, or simple C.  Postscript is a bit large to run on an AVR, but it is great for manipulating and parsing any sort of data in any language. 

 

Interesting enough the Ghostscript interpreter, is a perfect example of a community supported Open source platform.  Adobe demanded large license fees for their implementation of the 'language.'  They were also clever enough to put the spec of the language  in the public domain. Ideas are cheap, implementations are where the money is. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
EDIT seems to be still going with V1.51 for Mega644 as of 26.3.2017

http://www.jcwolfram.de/download...

AttoBASIC is current up to Nov'16

An earlier variant had an EBI to a 32KB SRAM.

http://www.cappels.org/dproj/AttoBasic_Home/AttoBasic2v34/AttoBasic_Versions_2.34.html

via

Atto_Basic_V2)_Home

http://www.cappels.org/dproj/AttoBasic_Home/AttoBasic_Home.html

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rammon wrote:
- some thought that having a better PC/host program was the best, a program having some debug facilities too
Same with an Arduino interface from a C/C++ interpreter.

UC Davis Center for Integrated Computing and STEM Education

Ch Arduino

http://c-stem.ucdavis.edu/studio/charduino/

via

Ch -- an embeddable C/C++ interpreter, C and C++ scripting language

http://www.softintegration.com/

Ch is multi-platform and can run on one RTOS (BlackBerry QNX, down to arm Cortex-A53 Cortex-A5 in QNX v6)

 


http://www.softintegration.com/products/features.html

...

Ch Professional Edition for ARM (Raspberry Pi) is free for educational and personal use.

http://www.softintegration.com/store/

http://blackberry.qnx.com/en/developers/bsp

 

edit : strikethru

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Jul 5, 2019 - 08:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would be very surprised if there isn't a BASIC written in pure C. (probably made to show what you can make in C, I kind to remember that there was a book how to make interpreters. )

And when you have that it should be easy to add things.

And the benefit with C and not ASM is that you will get FP etc. for free.    

 

Add:

And today it's not a problem if the interpreter take up 16K flash, for most chips it would be the amount of RAM that would set the limit.

I would go for a mega1284 mostly because I have one but the 16 KRAM is nice.

My first computer had 7168 bytes free for basic as I remember. (PET) and that could hold a lot. 

Last Edited: Sun. Sep 9, 2018 - 04:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am sure that there will be a Basic interpreter somewhere.    I doubt if there is realistic support.

 

The biggest problem would be:   teaching your customers Basic.

 

Surely you would have any configurable logic in EEPROM.   And let the customer "program" it via HTML "app" on the internet.

Pure crystal Ball speculation.   

 

How do other PLCs work?    It would seem wise to follow existing convention.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

I've been asked how easy it would be to add user-defined functionality to an industrial controller unit. The unit is similar to an industrial PLC, it has digital, and analogue, inputs and outputs.

The ability is desired for ended users to be able to write instructions like...

"IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON"

In my mind I'm looking for something like the original Microsoft 8k or 12k 8-bit interpreter

So do we take that 8~12k as the maximum available code load added ?

What about RAM ?

What about Debug using  such a feature ? - you could  ask a better question of the one asking you 'how easy' is hack and hope ok to them ?

 

Brian Fairchild wrote:

, but written in C and  not assembler. And with commercial licence terms.

I can find plenty of 'tiny-basic' clones, lots of abandonware and lots written in assembly. But nothing fit for a commercial product.

 

Mandating C seems a little strange, ok for some 'nice to have' tickbox but the cornerstone need here, seems to be able to link with the build of you 'industrial controller unit'

 

ie abandonware is ok if the source is clearly coded ad commented

The IL (instruction list) example given in #22 looks a good start, because it uses an industry standard 

 

 

Brian Fairchild wrote:

The only code running on the PC/Mac/Linux box would, in an ideal world, be a VT100 terminal emulator.

Wow, so you expect those PC/Mac/Linux users to be ok to write low level PLC code, but not ok to install or run any software ?

 

The Debug/Development angle that was totally skipped over in #1,  looks to be well supported by the links in #24, but the base hardware they target in

https://openplc.discussion.commu...

is a 'TrimPI', so their firmware overhead is not really sounding anywhere near that 8k Binary

 http://wiki.friendlyarm.com/wiki...

Of course, that compact module with Ethernet, might just be small/cheap enough to include as a plug-in revision to your 'industrial controller unit'

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you think the aliens might have abducted Brian ?cheeky  Not much feedback since the original question.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
How do other PLCs work? 

See #7 ?

 

But he didn't actually say it is a PLC ... 

 

clawson wrote:
Do you think the aliens might have abducted Brian ?

Didn't he mention recently that he's on holiday ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
The only code running on the PC/Mac/Linux box would, in an ideal world, be a VT100 terminal emulator.

In this day and age, I think a Web Browser is probably more likely to be found on any arbitrary computer ... ?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Do you think the aliens might have abducted Brian ?cheeky  Not much feedback since the original question.

Hehe, yes, meanwhile  I was musing on other pathways using this "but the cornerstone need here, seems to be able to link with the build of your 'industrial controller unit'"

 

So I took this command line 

 

fbc.exe" -g -gen gcc -r -v Test.bas

 

to compile this snippet

 

Function RdCNT()  As uinteger

  return CUint(Timer/tP1_CLK)

end function

 

Sub WAITCNT (WaitForwardValue As uinteger)

  VAR SleepRounded = ((WaitForwardValue-RdCNT())/t1ms)-21   ' 20ms OK, Experimental trim-down, need finite loops 16,18ms fail 19ms is marginal, choose 21ms - test on other PC's ?

  if SleepRounded >= 0 then 

    Sleep(SleepRounded)  'round down, so most of time is Sleep, 

  end if  

  Var AbsDiff = ABS(WaitForwardValue-RdCNT() )     ' 99% of time this is small, but in rare cases, RdCNT will be MAX, and WaitForwardValue will have wrapped 

  PollCheck = 0

  StartD = Timer()

  While AbsDiff >= ABS(WaitForwardValue-RdCNT() )  ' look for reversal of setpoint diff, diff decreases until it hits match, then starts to increase.

   AbsDiff = ABS(WaitForwardValue-RdCNT() )

   PollCheck = PollCheck + 1

  wend 

  EndD = Timer()

end Sub

 

creates :

 

 

static uint32 POLLCHECK$

 

void __stdcall fb_End( int32 );

double __stdcall fb_Timer( void );

void __stdcall fb_Sleep( int32 );

 

 

uint32 __stdcall RDCNT( void )

#line 134 "Test.bas"

{

#line 134 "Test.bas"

uint32 fb$result$1;

#line 134 "Test.bas"

__builtin_memset( &fb$result$1, 0, 4 );

#line 134 "Test.bas"

label$65:;

// return CUint(Timer/tP1_CLK)

#line 135 "Test.bas"

double vr$1 = fb_Timer(  );

#line 135 "Test.bas"

fb$result$1 = (uint32)fb_D2L( vr$1 / 0x1.AD7F29ABCAF48p-27 );

#line 135 "Test.bas"

goto label$66;

#line 136 "Test.bas"

label$66:;

#line 136 "Test.bas"

return fb$result$1;

#line 136 "Test.bas"

}

#line 138 "Test.bas"

void __stdcall WAITCNT( uint32 WAITFORWARDVALUE$1 )

#line 138 "Test.bas"

{

#line 138 "Test.bas"

label$67:;

// VAR SleepRounded = ((WaitForwardValue-RdCNT())/t1ms)-21 

#line 139 "Test.bas"

double SLEEPROUNDED$1;

#line 139 "Test.bas"

uint32 vr$0 = RDCNT(  );

#line 139 "Test.bas"

SLEEPROUNDED$1 = ((double)(WAITFORWARDVALUE$1 - vr$0) / 0x1.388p+16) + -0x1.5p+4;

// if SleepRounded >= 0 then

#line 140 "Test.bas"

if( SLEEPROUNDED$1 < 0x0p+0 ) goto label$70;

{

// Sleep(SleepRounded)  

#line 141 "Test.bas"

fb_Sleep( fb_D2I( SLEEPROUNDED$1 ) );

// end if

}

#line 142 "Test.bas"

label$70:;

#line 142 "Test.bas"

label$69:;

// Var AbsDiff = ABS(WaitForwardValue-RdCNT() )    

#line 143 "Test.bas"

uint32 ABSDIFF$1;

#line 143 "Test.bas"

uint32 vr$6 = RDCNT(  );

#line 143 "Test.bas"

ABSDIFF$1 = __builtin_abs( (WAITFORWARDVALUE$1 - vr$6) );

// PollCheck = 0

#line 144 "Test.bas"

POLLCHECK$ = 0u;

// StartD = Timer()

#line 145 "Test.bas"

double vr$9 = fb_Timer(  );

#line 145 "Test.bas"

STARTD$ = vr$9;

// While AbsDiff >= ABS(WaitForwardValue-RdCNT() )  

#line 146 "Test.bas"

label$71:;

#line 146 "Test.bas"

uint32 vr$10 = RDCNT(  );

#line 146 "Test.bas"

if( ABSDIFF$1 < __builtin_abs( (WAITFORWARDVALUE$1 - vr$10) ) ) goto label$72;

{

// AbsDiff = ABS(WaitForwardValue-RdCNT() )

#line 147 "Test.bas"

uint32 vr$13 = RDCNT(  );

#line 147 "Test.bas"

ABSDIFF$1 = __builtin_abs( (WAITFORWARDVALUE$1 - vr$13) );

// PollCheck = PollCheck + 1

#line 148 "Test.bas"

POLLCHECK$ = POLLCHECK$ + 1u;

// wend

}

#line 149 "Test.bas"

goto label$71;

#line 149 "Test.bas"

label$72:;

// EndD = Timer()

#line 150 "Test.bas"

double vr$17 = fb_Timer(  );

#line 150 "Test.bas"

ENDD$ = vr$17;

#line 151 "Test.bas"

label$68:;

#line 151 "Test.bas"

}

 

..

// Var LoopC = 0

#line 122 "COM4_Test.bas"

int32 LOOPC$0;

#line 122 "COM4_Test.bas"

LOOPC$0 = 0;

// WHILE LoopC < 60

label$63:;

if( LOOPC$0 >= 60 ) goto label$64;

{

LOOPC$0 = LOOPC$0 + 1;

// WEND

}

goto label$63;

label$64:;

 

Looks like a coarse skeleton is there, but default types may be an issue, and it may be better to give them compatible subroutines like the Scaled timer here, that a simple dictionary table script 

With an example framework that shows what your system does support, maybe something usable could be crafted ?

 

A benefit of their c generated code, is you could debug the whole linked binary in Atmel Studio. (once it all finally compiled and linked  ;) ) 

 

LoopC looks portable, but PollCheck is declared Shared in FreeBASIC, so seems to have different declaration.  Maybe that's fine in GCC ?

 

...and I checked other type-casts, with 'interesting results'. Looks like they expect a native UInt32 Mathops target, so whilst the VAR declaration is  precise, the generated code is not going to be compact of fast ?

Or you just use a rule, like let them have a few 32b variables ?

 

// Var Loop8u = Cast(UBYTE, 0)

uint8 LOOP8U$0;

LOOP8U$0 = (uint8)0u;

// WHILE Loop8u < 60

label$65:;

if( (int32)LOOP8U$0 >= 60 ) goto label$66;

{

// Loop8u = Loop8u +1

LOOP8U$0 = (uint8)((int32)LOOP8U$0 + 1);

// WEND

}

goto label$65;

label$66:;

// Var Loop16u = Cast(USHORT, 0)

uint16 LOOP16U$0;

LOOP16U$0 = (uint16)0u;

// WHILE Loop16u < 60

label$67:;

if( (int32)LOOP16U$0 >= 60 ) goto label$68;

{

// Loop16u = Loop16u +1

LOOP16U$0 = (uint16)((int32)LOOP16U$0 + 1);

// WEND

}

goto label$67;

label$68:;

 

 

// Var Loop16i = Cast(SHORT, 0)

int16 LOOP16I$0;

LOOP16I$0 = (int16)0;

// WHILE Loop16i < 60

label$69:;

if( (int32)LOOP16I$0 >= 60 ) goto label$70;

{

// Loop16i = Loop16i +1

LOOP16I$0 = (int16)((int32)LOOP16I$0 + 1);

// WEND

}

goto label$69;

label$70:;

Last Edited: Mon. Sep 10, 2018 - 10:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
"IF (digi-input4 = HIGH) AND (ana_input7 > 100) THEN digi-output3 = ON"

 

Focusing on this line, we find (basic source code as comments)

 

// IF di_4 AND (AnI7 > 100) THEN

if( (-DI_4$0 & -(ANI7$0 > 100)) == 0 ) goto label$3;

{

// do_2 = True

DO_2$0 = (boolean)1;

// END IF

}

 

and the variables declare as these

int32 ANI7$0;

int32 ANI0$0;

boolean DI_4$0;

boolean DO_2$0;

 

 

 

and types are managed as 

 

typedef   signed char       int8;

typedef unsigned char      uint8;

typedef   signed short      int16;

typedef unsigned short     uint16;

typedef   signed int        int32;

typedef unsigned int       uint32;

typedef   signed long long  int64;

typedef unsigned long long uint64;

typedef struct { char *data; int32 len; int32 size; } FBSTRING;

typedef int8 boolean;

 

int32 and int8  show booleans are passed

Last Edited: Tue. Sep 11, 2018 - 02:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

clawson wrote:

Do you think the aliens might have abducted Brian ?cheeky  Not much feedback since the original question.

 

Not aliens but sunday roasts, pasties, cider, coastal walks, sunshine, fresh air, and other holiday stuff. This is my view yesterday morning as I sipped my morning coffee...

 

 

 

...now be honest. Which would you choose? cheeky

 

I have been reading the replies on my phone and will post a reply after breakfast.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TCL is an option.

PARTCL seems quite small simple and extensible...

https://zserge.com/blog/tcl-inte...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess this is "too big" (55K flash) ?

 

https://code.google.com/archive/...

 

Shame because there's a lot to like about Python which is (apparently) fast becoming the most used programming language these days.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The first Arduino is the ‘master’. Oh, my!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not super fond of Python, and it's definitely an awful choice for something AVR-sized. Garbage-collected pointer-heavy languages are not a good fit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indiana Jones is not font of Python either.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly