DMX512 interface - LEnsE / VILLEMEJANE

Dependencies:   mbed mbed-dsp

Files at this revision

API Documentation at this revision

Comitter:
villemejane
Date:
Tue Feb 09 14:33:50 2021 +0000
Parent:
0:96c89b4dc711
Commit message:
DMX512 interface - LEnsE / VILLEMEJANE

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 96c89b4dc711 -r 76fbb91a0331 main.cpp
--- a/main.cpp	Tue Dec 08 12:10:01 2020 +0000
+++ b/main.cpp	Tue Feb 09 14:33:50 2021 +0000
@@ -1,66 +1,69 @@
-#include "mbed.h"
-#include "arm_math.h"
-/* Include mbed-dsp libraries */
-#include "dsp.h"
-#include "arm_common_tables.h"
-#include "arm_const_structs.h"
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
-#define SAMPLES                 512             /* 256 real party and 256 imaginary parts */
-#define FFT_SIZE                SAMPLES / 2     /* FFT size is always the same size as we have samples, so 256 in our case */
- 
-float32_t Input[SAMPLES];
-float32_t Output[FFT_SIZE];
-bool      trig=0;
-int       indice = 0;
+#include "mbed.h"
+
+#define SAMPLES     512 
+Serial      debug_pc(USBTX, USBRX);
 
-DigitalOut myled(LED1);
-AnalogIn   myADC(A0);
-AnalogOut  myDAC(A2);
-Serial     pc(USBTX, USBRX);
-Ticker     timer;
- 
-void sample(){
-    myled = 1;
-    if(indice < SAMPLES){
-        Input[indice] = myADC.read() - 0.5f;    //Real part NB removing DC offset
-        Input[indice + 1] = 0;                  //Imaginary Part set to zero
-        indice += 2;
-    }
-    else{ trig = 0; }
-    myled = 0;
-}
- 
+Serial      dmx(PC_10, PC_11);
+DigitalOut  out_tx(D10);
+DigitalOut  start(D11);
+DigitalOut  enableDMX(D5);
+
+AnalogIn    variationR(A0);
+AnalogIn    variationG(A1);
+AnalogIn    variationB(A2);
+
+DigitalIn   my_bp(USER_BUTTON);
+
+char dmx_data[SAMPLES] = {0};
+char nb = 0;
+
+void dmx_update();
+
 int main() {
-    float maxValue;            // Max FFT value is stored here
-    uint32_t maxIndex;         // Index in Output array where max value is
-
+    debug_pc.baud(9600);
+    debug_pc.printf("Essai DMX512\r\n");
+    dmx.baud(250000);
+    dmx.format (8, SerialBase::None, 2);
+    enableDMX = 0;
+    
+    // Eurolite LED H2O - 5 channels / adress 0
+    dmx_data[0] = 0x00;     // Red
+    dmx_data[1] = 0x00;     // Green
+    dmx_data[2] = 0x00;     // Blue
+    dmx_data[3] = 0xFF;     // Dimmer - Max = 255
+    dmx_data[4] = 0x00;     // On = 0
+    
     while(1) {
-        if(trig == 0){
-            timer.detach();
-            // Init the Complex FFT module, intFlag = 0, doBitReverse = 1
-            //NB using predefined arm_cfft_sR_f32_lenXXX, in this case XXX is 256
-            arm_cfft_f32(&arm_cfft_sR_f32_len256, Input, 0, 1);
- 
-            // Complex Magniture Module put results into Output(Half size of the Input)
-            arm_cmplx_mag_f32(Input, Output, FFT_SIZE);
-            Output[0] = 0;
-            //Calculates maxValue and returns corresponding value
-            arm_max_f32(Output, FFT_SIZE/2, &maxValue, &maxIndex);
-        
-            myDAC=1.0;     //SYNC Pulse to DAC Output
-            wait_us(20);    //Used on Oscilliscope set trigger level to the highest
-            myDAC=0.0;     //point on this pulse 
-    
-            for(int i=0; i < FFT_SIZE / 2; i++){
-                myDAC=(Output[i]) * 0.9;   // Scale to Max Value and scale to 90 / 100
-                wait_us(10);                //Each pulse of 10us is 50KHz/256 = 195Hz resolution
-            }
-            myDAC=0.0;
-            pc.printf("MAX = %lf, %d \r\n", maxValue, maxIndex);
-            wait(0.2);
-            trig = 1;
-            indice = 0;
-            timer.attach_us(&sample,40);      //20us 50KHz sampling rate
+        int valeur = variationR.read_u16() >> 8;
+        dmx_data[0] = valeur;  
+        valeur = variationG.read_u16() >> 8;
+        dmx_data[1] = valeur;
+        valeur = variationB.read_u16() >> 8;
+        dmx_data[2] = valeur;    
+        dmx_data[4] = 0;    // on
+        dmx_update();
+        wait_us(100000);
+    }
+}
+
+
+void dmx_update(){
+        enableDMX = 1;
+        start = 1;      // /start
+        out_tx = 0;     // break
+        wait_us(88);    
+        out_tx = 1;     // mb
+        wait_us(8);     
+        out_tx = 0;     // break
+        start = 0;
+        dmx.putc(0x00);     // Start
+        for(int i = 0; i < SAMPLES; i++){
+            dmx.putc(dmx_data[i]);     // data
         }
-    }
+        wait_us(23000); // time between frame  
 }
\ No newline at end of file