Bit banging a serial to parallel shift register to drive a 7 segment display is very slow. #7778
-
I am trying to write a display multiplexer by bit banging a 16 bit register to an external serial to parallel shift register. The issue is that the code is running very slowly! I have tried to see how fast the device will run by writing a very simple while loop which sets and clears a pin (while(true){digitalWrite(D6,0);digitalWrite(D6,1):}) On the Espurino this code produces a square wave of about 4kHz. The same code running on a MicroBit using Make Code produces a square wave of about 300kHz. If i flash the Micro Bit with Espurino and run the code i get 4kHz. The issue must therefore be the Espurino code rather than the hardware. Does anyone have any thoughts or ideas as to how i can improve the performance. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Hi, As I understand it, Microsoft Make:code actually does some compilation on the code you write, so it's going to be a bit faster than running the JS which is interpreted from the text on the fly. Espruino has a bunch of options though...
There are other options too, but those are going to be the easiest/best. |
Beta Was this translation helpful? Give feedback.
-
Which version of Microbit it is? The old V1 is nrf51822 and has small RAM and flash size so not much can be enabled there but nowadays the 'normal' Microbit is V2 which is nrf52833 and there both JIT and the inline C compiler could be used. However for inline C you need to run your own server on local machine and JIT is currently not enabled. Is there a reason to not enable JIT here by default?https://github.com/espruino/Espruino/blob/a454207e03449be32c06bde013d4b0439813eba5/boards/MICROBIT2.py#L43 EDIT: with JIT enabled it builds as is with patch below and everything fits. I will test with real device. And BTW we already have 128k RAM enabled so some board comments/values are wrong(?) diff --git a/boards/MICROBIT2.py b/boards/MICROBIT2.py
index d0e428427..8a4418874 100644
--- a/boards/MICROBIT2.py
+++ b/boards/MICROBIT2.py
@@ -17,7 +17,6 @@ import pinutils;
# TODO:
# Move to SDK17 with proper nRF52833 support
-# - expand RAM to 128k
# Proper event handling for accelerometer/etc
# Functions for sound
@@ -39,7 +38,8 @@ info = {
# 'NET',
'GRAPHICS',
'NEOPIXEL',
- 'TENSORFLOW'
+ 'TENSORFLOW',
+ 'JIT'
],
'makefile' : [
'DEFINES += -DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
@@ -59,9 +59,9 @@ chip = {
'part' : "NRF52832", # actually 52833 but we're using SDK12 for this at the moment, and it doesn't support it
'family' : "NRF52",
'package' : "QFN48",
- 'ram' : 64,
+ 'ram' : 128, # increased by LD_SRAM_SIZE=0x20000 above
'flash' : 512,
- 'speed' : 64, # TODO: actually 128k
+ 'speed' : 64,
'usart' : 1,
'spi' : 1,
'i2c' : 1, |
Beta Was this translation helpful? Give feedback.
Hi,
As I understand it, Microsoft Make:code actually does some compilation on the code you write, so it's going to be a bit faster than running the JS which is interpreted from the text on the fly. Espruino has a bunch of options though...
E.shiftOut
function which basically bit-bangs for you: https://www.espruino.com/Reference#l__global_shiftOutSPI
- hardware or even software SPI should be pretty quick and you can run it on whatever pins you want. You just convert the 16 bit number into 2 8 bit numbers which you can do withnew Uint16Array([number]).buffer