I will use the next days to wrap up a working version of the VM so I can test code footprint and performance. What I expect is actually quite high overall performance. Each instruction will be significantly slower than an ARM instruction -probably in the region of 1:1000, so I am hoping for an instruction speed of 50,000++. This will however be a learning experience.
Raw performance alone is however not that important, having a responsive system that we can use to control advanced operations with a few lines of code is. With a correct written Plain application a module will spend it’s life in idle waiting for an event from C code and respond to that.
Use System Module Servo32 Enum Byte ChannelMode DigitalIn DigitalOut AnalogueIn AnalogueOut PWMOut Servo End Object Channel ChannelMode mode uint32 frequency uint32 duty uint32 servoPosition real32 analogueValue bit digitalValue End External C Channel chan External C Func UpdateChannel(uint32 c) Event FrequencyError Event DutyError Event PositionError Event AnalogueError End External C Func EnableEvent(uint32 c) External C Event ChannelChanged(uint32 c) if(chan[c].digitalValue=1) chan[c-4].servoPosition = 180 else chan[c-4].servoPosition = 0 end UpdateChannel(c-4) End int16 x for x=1 to 4 chan[x].mode = ChannelMode.Servo chan[x].frequency=50 chan[x].servoPosition=0 UpdateChannel (x) end for x=5 to 8 chan[x].mode = ChannelMode.DigitalIn UpdateChannel (x) end for x=5 to 8 EnableEvent(x) end End
The code snip above is an attempt to create a test program for the 32 x Servo/IO Hat. In this case I connect 4 servoes to channel 1-4 and a digital switch to channel 5-8. If I set channel 5 high I want servo 1 to move to pos 180 etc.
The actual Plain program is in this case 20 instructions and probably < 200 bytes of stored instruction Space.
Pay attention to event “ChannelChanged“. The rest of the code is just configuration, this event is the actual control code. What should happen is that as the digital input on channel 5-8 change we receive a call from C code and change the relevant servo channel as a response. After that we go back to idle and just wait for an event.
Binding to C code is planned to be done automatically by “External C”. In the example of ChannelEvent the RTL will expect to find a C event with that exact name and parameter. It’s too early to say if this will stand ground as I implement the VM – lets see.