1
0
Pārlūkot izejas kodu

bug: servo in 4 bit mode evaluate full 8 bit

Klaas, Wilfried 2 gadi atpakaļ
vecāks
revīzija
b3c53b7551
5 mainītis faili ar 123 papildinājumiem un 23 dzēšanām
  1. 16 10
      README.md
  2. 51 0
      SPS/EEPROM_mbv2.h
  3. 15 8
      SPS/SPS.ino
  4. 36 0
      SPS/hardware.h
  5. 5 5
      SPS/prgmode.ino

+ 16 - 10
README.md

@@ -8,8 +8,14 @@ http://www.rcarduino.de/doku.php?id=en:arduino:arduinosps
 And there is now a print book at amazon 
 https://www.amazon.com/dp/1731232535
 
+**Version 0.12.2**
+  07.06.2021
+
+  - bug with servo in 4-bit mode, evaluate the full 8 bit.
+
 **Version 0.12.1**
   03.09.2019
+
   - changing the variable names in debug mode
   - release
 
@@ -17,9 +23,9 @@ https://www.amazon.com/dp/1731232535
   27.01.2019
   - Release
   - automatically adding demo program to new mcu
-  11.01.2018
+    11.01.2018
   - some refactoring
-  
+
   07.01.2018
   - programming: 1/2 duty cycle for 0 values in address display
 
@@ -31,17 +37,17 @@ https://www.amazon.com/dp/1731232535
 **Version 0.10**
   9.12.2018
   - Release
-  
+
   7.12.2018
   - new define for serial programming
 
   18.11.2018 WKLA
   - new standard programming mode
-  I added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
-  The new one has a nicer interface, as you now always know where you are.
-  Starting with PRG pushed after Reset.
-  as a result, all LEDs will shortly blink
-  now you are in programming mode.
+    I added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
+    The new one has a nicer interface, as you now always know where you are.
+    Starting with PRG pushed after Reset.
+    as a result, all LEDs will shortly blink
+    now you are in programming mode.
   * the D1 LED will blink
   * the higher nibble of the address will be shown
   * the D2 LED will blink
@@ -62,7 +68,7 @@ https://www.amazon.com/dp/1731232535
 **Version 0.9**
   18.11.2018 WKLA
   * BUGs entfernt. Release.
-  10.11.2018 WKLA
+    10.11.2018 WKLA
   * Implementierung Tone Befehl
 
 **Version 0.8**
@@ -80,7 +86,7 @@ https://www.amazon.com/dp/1731232535
   * es können bis zu 6 Unterroutinen definiert werden und diese direkt angesprungen werden.
   * neben return gibt's auch einen restart
   * 2 Servoausgänge für übliche RC Servos. (10° Auflösung in Nibble Modus, <1° Auflösung im Bytemodus)
-  ACHTUNG: Servo und PWM Ausgänge sind nicht mischbar und können auch nicht gleichzeitig benutzt werden.
+    ACHTUNG: Servo und PWM Ausgänge sind nicht mischbar und können auch nicht gleichzeitig benutzt werden.
   * 2 RC Eingänge (16 Schritte auflösung im nibble Modus, Mitte 8, 255 Schritte im Byte Modus)
   * fkt. auch mit einem ATTiny84 (44 ist leider auf GRund der Programmgröße nicht mehr für den erweiterten Befehlssatz möglich)
   * call stack von bis zu 16 Unterfunktionen

+ 51 - 0
SPS/EEPROM_mbv2.h

@@ -0,0 +1,51 @@
+/* this is the eeprom abstraction for the microbit v2. 
+ *  the eeprom will be mapped to a simple file in the file system, later.
+ */
+#ifdef _MICROBIT_V2_
+
+const int STORESIZE = 256;
+byte program[STORESIZE];
+bool loaded = false;
+
+void load() {
+  loaded = true;
+}
+
+byte readbyte(int addr) {
+  if (!loaded) {
+    load();
+  }
+  if ((addr >=0) && (addr < STORESIZE)) {
+    return program[addr];
+  }
+  return 0xFF;
+}
+
+void writebyte(int addr, byte value) { 
+  if ((addr >=0) && (addr < STORESIZE)) {
+    program[addr] = value;
+  }
+}
+
+void store() {
+}
+
+#else
+
+#include <EEPROM.h>
+#include <avr/eeprom.h>
+
+const int STORESIZE = E2END;
+
+byte readbyte(int addr) {
+  return EEPROM.read(addr);
+}
+
+void writebyte(int addr, byte value) {
+  EEPROM.write(addr, value);
+}
+
+void store() {
+}
+
+#endif

+ 15 - 8
SPS/SPS.ino

@@ -1,5 +1,13 @@
 /*
   SPS System mit dem Arduino.
+  Version 0.12.2
+  07.06.2021
+  - bug with servo in 4-bit mode, evaluate the full 8 bit.
+
+  Version 0.12.1
+  03.09.2019
+  - changing the variable names in debug mode
+  
   Version 0.12
   27.01.2019
   - adding demo program,
@@ -113,8 +121,7 @@
 // libraries
 #include <debug.h>
 #include <makros.h>
-#include <EEPROM.h>
-#include <avr/eeprom.h>
+#include "EEPROM_mbv2.h"
 
 #ifdef SPS_SERVO
 #include <Servo.h>
@@ -267,8 +274,8 @@ void doReset() {
 void readProgram() {
   dbgOutLn("Read program");
   word addr = 0;
-  for ( addr = 0; addr <= E2END; addr++) {
-    byte value = EEPROM.read(addr);
+  for ( addr = 0; addr <= STORESIZE; addr++) {
+    byte value = readbyte(addr);
 
 #ifdef debug
     dbgOut2(value, HEX);
@@ -329,7 +336,7 @@ void readProgram() {
   main loop
 */
 void loop() {
-  byte value = EEPROM.read(addr);
+  byte value = readbyte(addr);
   byte cmd = (value & 0xF0);
   byte data = (value & 0x0F);
 
@@ -385,7 +392,7 @@ void loop() {
     default:
       ;
   }
-  if (addr > E2END) {
+  if (addr > STORESIZE) {
     doReset();
   }
 }
@@ -629,7 +636,7 @@ void doIsA(byte data) {
 #ifdef SPS_SERVO
     case 11:
       if (servo1.attached()) {
-        tmpValue = (a * 10) + 10;
+        tmpValue = ((a & 0x0f) * 10) + 10;
         dbgOut("Srv1:");
         dbgOutLn(tmpValue);
         servo1.write(tmpValue);
@@ -637,7 +644,7 @@ void doIsA(byte data) {
       break;
     case 12:
       if (servo2.attached()) {
-        tmpValue = (a * 10) + 10;
+        tmpValue = ((a & 0x0f) * 10) + 10;
         dbgOut("Srv2:");
         dbgOutLn(tmpValue);
         servo2.write(tmpValue);

+ 36 - 0
SPS/hardware.h

@@ -129,3 +129,39 @@ const byte SERVO_2 = 12;
 const byte SW_PRG = 9;
 const byte SW_SEL = 8;
 #endif
+
+#ifdef _MICROBIT_V2_
+// Microbit V2 Hardware
+const byte Din_0 = 0;
+const byte Din_1 = 1;
+const byte Din_2 = 2;
+const byte Din_3 = 3;
+
+const byte Dout_0 = 4;
+const byte Dout_1 = 5;
+const byte Dout_2 = 6;
+const byte Dout_3 = 7;
+
+const byte ADC_0 = 0; //(15)
+const byte ADC_1 = 1; //(16)
+const byte PWM_1 = 9;
+const byte PWM_2 = 10;
+
+#ifdef SPS_RCRECEIVER
+const byte RC_0 = 18;
+const byte RC_1 = 19;
+#endif
+
+#ifdef SPS_SERVO
+const byte SERVO_1 = 9;
+const byte SERVO_2 = 10;
+#endif
+
+const byte SW_PRG = 8;
+const byte SW_SEL = 11;
+
+#ifdef SPS_USE_DISPLAY
+const byte DIGIT_DATA_IO = 12;
+const byte DIGIT_CLOCK = 13;
+#endif
+#endif

+ 5 - 5
SPS/prgmode.ino

@@ -19,12 +19,12 @@ enum PROGRAMMING_MODE {ADDRESS, COMMAND, DATA};
 PROGRAMMING_MODE prgMode;
 
 void prgDemoPrg() {
-  byte value = EEPROM.read(0);
+  byte value = readbyte(0);
   if (value == 0xFF) {
-    value = EEPROM.read(1);
+    value = readbyte(1);
     if (value == 0xFF) {
       for (byte i = 0; i < sizeof(demoPrg); i++) {
-        EEPROM.write(i, demoPrg[i]);
+        writebyte(i, demoPrg[i]);
       }
     }
   }
@@ -61,7 +61,7 @@ void programMode() {
       doAddr(data);
       //delay(SHOW_DELAY);
 
-      byte Eebyte = EEPROM.read(addr);
+      byte Eebyte = readbyte(addr);
       data = Eebyte & 15;
       com = Eebyte >> 4;
 
@@ -99,7 +99,7 @@ void programMode() {
 
       byte newValue = (com << 4) + data;
       if (newValue != Eebyte) {
-        EEPROM.write(addr, newValue); //           Writeeeprom Eebyte , Addr
+        writebyte(addr, newValue); //           Writeeeprom Eebyte , Addr
         blinkAll();
       }
       addr += 1;