test program to test / develop the SOLID slow control

Dependencies:   AD5384 SWSPI S25FL216K S_SCTRL_SMlib T_adt7320 adc_ad9249 sscm_comm mbed

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Mon Oct 06 11:02:10 2014 +0000
Parent:
1:17b3c72d8357
Child:
3:8b181fe62a39
Commit message:
temperature added;

Changed in this revision

AD5384.cpp Show diff for this revision Revisions of this file
AD5384.h Show diff for this revision Revisions of this file
AD5384.lib Show annotated file Show diff for this revision Revisions of this file
SWSPI.lib Show annotated file Show diff for this revision Revisions of this file
S_SCTRL_SMlib.lib Show annotated file Show diff for this revision Revisions of this file
T_adt7320.lib Show annotated file Show diff for this revision Revisions of this file
adc_ad9249.lib Show annotated file Show diff for this revision Revisions of this file
adt7320.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sscm_comm.lib Show annotated file Show diff for this revision Revisions of this file
--- a/AD5384.cpp	Tue Sep 23 08:30:04 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-#include "AD5384.h"
-
-
-#include "mbed.h"
-
-#define  nrch 40 // nr channels 
-#define  p2_14  163834
-#define  p2_13  8192
-
-#define C_ACTIVE 0
-#define C_DEACTIVE  1
-
-
-// spi mode has to be set for each transmission as spi bus can be shared 
-
-
-
-
-AD5384::AD5384(SWSPI *spiinterface ,DigitalOut* chipselect) {
-        vref=2.5; 
-        spi=spiinterface; 
-        cs=chipselect;
-        for ( int nc=0 ; nc < nrch; nc++){
-            gain[nc]=0x3FFE;
-            offset[nc]=0x2000;
-        } 
-    };
-    
-    u16  AD5384::calculate_dac_setting(u8 nr, float vout ) {  
-    //Vout = 2 * Vref * x2 / 2^n  =>  x2 = Vout * 2^14 /(2 * Vref) 
-    // x2 is loaded to the DAC string  
-    // x1 is the 14 bit DAC wordt written to the DAC input register 
-                if( nr >39 ) return 0;
-                float x2= vout * p2_14 /(2 *vref);
-    //  x2 = [(gain+2)/2^n * x1] + offset-2^13               
-    // x1 = 2^14/(gain+2) *  [ x2 - offset+2^13 ]
-                u16 x1 = p2_14/(gain[nr]+1) *( x2- offset[nr]+p2_13);
-                dac[nr]=x1 ;
-                return x1;
-             };
-
-
-u32 AD5384::format_word(u8 mode,u8 ch,u8 rw,u16 data) {
-      // not clear what is the MSB bit ,set  it to zero           
-            u32 word= (rw&1) << 22;
-            u32 shift = ((u32)ch &0x1F) << 14;
-            word = word | shift;
-            shift = ((u32)mode & 0x3) << 13;
-            word = word | shift;
-            word = word | (data & 0x3FF);
-            return word;
-}
-             
-void AD5384::set_spi_mode(){
-    spi->format(24,0);
-    spi->frequency(10000000);             
-}
-             
- void AD5384::set_volt(u8 ch, float vout ){
-     volt[ch]=vout;
-     u16 dacin=calculate_dac_setting(ch,  vout );
-     set_spi_mode();
-     u32 data=format_word(3,ch,0,dacin); 
-     cs->write(C_ACTIVE);
-     spi->write(data);
-     cs->write(C_DEACTIVE);   
-}
-
--- a/AD5384.h	Tue Sep 23 08:30:04 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-#ifndef AD5384_H
-#define AD5384_H
-
-#include "solid_sctrl_def.h"
-#include "SWSPI.h"
-
-/*
- * class to set and readback the AD5384
- * to minimize the access to the device there is a shadow of the DAC, GAIN and OFFSET values 
-    
- * V 0.1  inital development to see if reading / writing is possible    
-*/ 
-class SWSPI;
-#include "mbed.h"
-//class DigitalOut;
-
-class AD5384  {
-    SWSPI *spi ;
-    DigitalOut* cs; 
-    float vref;
-    
-    void set_spi_mode();
-    u16 calculate_dac_setting(u8 nr, float vout );
-    u32 format_word(u8 mode,u8 ch,u8 rw,u16 data) ;
-    public: 
-        AD5384(SWSPI *spiinterface ,DigitalOut* chipselect );
-        
-        u16 dac[40];
-        u16 gain[40];
-        u16 offset[40];
-        float volt[40];
-        
-        
-        void  set_volt(u8 nr, float vout );
-};
-
-#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD5384.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/wbeaumont/code/AD5384/#d2d6341d3e97
--- a/SWSPI.lib	Tue Sep 23 08:30:04 2014 +0000
+++ b/SWSPI.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wbeaumont/code/SWSPI/#02327a96a5e2
+http://mbed.org/users/wbeaumont/code/SWSPI/#9c5ae1507a81
--- a/S_SCTRL_SMlib.lib	Tue Sep 23 08:30:04 2014 +0000
+++ b/S_SCTRL_SMlib.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wbeaumont/code/S_SCTRL_SMlib/#20f21cb7792e
+http://mbed.org/users/wbeaumont/code/S_SCTRL_SMlib/#1cae1504a800
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/T_adt7320.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/wbeaumont/code/T_adt7320/#1b9f706b8abc
--- a/adc_ad9249.lib	Tue Sep 23 08:30:04 2014 +0000
+++ b/adc_ad9249.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wbeaumont/code/adc_ad9249/#9efb460e962b
+http://mbed.org/users/wbeaumont/code/adc_ad9249/#01459a6ab296
--- a/adt7320.h	Tue Sep 23 08:30:04 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef ADT7320_H
-#define ADT7320_H
-
-/* 
-
- adt7320 interface 
-
-*/
-class spi_v; 
-
-class at7320 {
-
-    
-public:
-
-float getTemperature();    
-    
-};
-
-
-
-
-#endif 
\ No newline at end of file
--- a/main.cpp	Tue Sep 23 08:30:04 2014 +0000
+++ b/main.cpp	Mon Oct 06 11:02:10 2014 +0000
@@ -5,11 +5,12 @@
 #include "S25FL216K.h"
 #include "AD5384.h"
 #include "AD9249.h"
+#include "adt7320.h"
 #include "S_SCTRL_SM1_PinDef.h" 
 #include "S_SCTRL_SM1_hwfunct.h" 
 
-#define VERSION 1
-#define SUBVERSION 3
+#define VERSION "1.23"
+
 #define DEBUGPF(x) printf((x));
 // pin function         pin id 
 // SPI 1 
@@ -29,7 +30,9 @@
 
 //++++++++++++++++++++++
   int main()   {   
-        
+    bool testADC=false;
+    bool testDAC=true;  
+    bool testTEMP=false;//true;
        pc.attach(&callback);// handles the input on the RS232 interface  
     HWlines  hwl ;
     assignports( &hwl );
@@ -46,12 +49,14 @@
      
       AD5384 dac[2]={AD5384(&spi,hwl.dac_cs[0]), AD5384(&spi2,hwl.dac_cs[1]) };
       
+      adt7320 temp[2][3]= { adt7320(&spi, hwl.t_cs[0]),adt7320(&spi, hwl.tc_cs1[0]),adt7320(&spi, hwl.tc_cs2[0]),
+                            adt7320(&spi2, hwl.t_cs[1]),adt7320(&spi2, hwl.tc_cs1[1]),adt7320(&spi2, hwl.tc_cs2[1]) };
       //float humi;
       
       
       
       DEBUGPF("start");
-      printf(" version  %d.%02d  compiled %s %s \n\r" , VERSION , SUBVERSION, __DATE__, __TIME__ );
+      printf(" version  %s compiled %s %s \n\r" , VERSION , __DATE__, __TIME__ );
       printf(" boardserialnr %d \n\r", get_serialnr(&hwl));
       u8 consel1=0;
       u8 consel2=1;
@@ -69,46 +74,55 @@
         adc[cc][1].getDevInfo(id,grade);printf(" %d %d ",id, grade);
         
       }*/
+      // init parts
+      for (u8 cc= conls; cc < conle ; cc++) {
+          if( testDAC) { dac[cc].init1();
+        }
+      }
+      
       u32 count =0;
       while(1)   {
         for (u8 cc= conls; cc < conle ; cc++) {
-        u16 rb,rb2;      
-        adc[cc][0].getDevId(id);
-        adc[cc][0].getGrade(grade);
-        //adc[cc][0].getDevInfo(id,grade,rb);
-        printf("id %02X grade %02X",id, grade );
-        printf("\n\r");
-        adc[cc][0].setPattern1(0x1235);
-        adc[cc][0].setPattern2(0xA5FF);
-        adc[cc][0].readPattern1(rb);       
-        adc[cc][0].readPattern2(rb2);
-        printf("pattern1 %04X  pattern2 %04X",rb,rb2);
-        printf("\n\r");
-       // dac[cc].set_volt(count%32,count%163834);
-       }
-        wait(.5);count++;
-        
+            u16 rb,rb2; 
+            if( testADC) {     
+                adc[cc][0].getDevId(id);
+                adc[cc][0].getGrade(grade);
+                //adc[cc][0].getDevInfo(id,grade,rb);
+                printf("id %02X grade %02X",id, grade );
+                printf("\n\r");
+                adc[cc][0].setPattern1(0x1235);
+                adc[cc][0].setPattern2(0xA5FF);
+                adc[cc][0].readPattern1(rb);       
+                adc[cc][0].readPattern2(rb2);
+                printf("pattern1 %04X  pattern2 %04X",rb,rb2);
+                printf("\n\r");
+             }
+            if( testDAC ) {   
+                u16 dataread,dr2;
+                u8 ch =  count%32;
+                float value=2.742; // count%16383;
+                u16 gain=(count)%16383;//0x1235; 
+               //dataread=dac[cc].set_volt(ch,value);
+                dr2=dac[cc].set_dac(ch,gain);
+                wait(0.001);
+                dataread=dac[cc].get_dac(ch);
+                printf("ch %02X offset set to %04X ",ch,dr2);  
+                printf("readback %04X",dataread);
+                dataread=dac[cc].get_ctrl(); 
+                printf(" cntrl %04X\n\r",dataread);
+            }
+            if( testTEMP) {
+                u16 dataread ;
+                u8 id;
+                id=temp[cc][0].getId();
+                dataread=temp[cc][0].get_TcritSP();
+                printf( "temp chip ID %02X , Tcrit %04X \n\r", id, dataread);
+            }
+        }
+        wait(.25);count++;
         /*
-        DEBUGPF("spi2\n\r");
-        spi.format(8, 0);
-        spi.frequency(10000000);
-        cs.write(0);
-        spi.write(0x9f);
-        jedecid = (spi.write(0) << 16) | (spi.write(0) << 8) | spi.write(0);
-        cs.write(1);      
-        printf( "Jedec %d /n/r", jedecid);
+        flash.write(0,&c,1);
         
-        DEBUGPF("spi3\n\r");      
-        spi_adc.format(8,0);
-        spi_adc.frequency(10000000);
-        cs_adc.write(0);
-        spi_adc.write(0x9f);
-        jedecid = (spi_adc.write(0) << 16) | (spi_adc.write(0) << 8) | spi_adc.write(0);
-        cs_adc.write(1);
-        char c=0x12;
-        flash.write(0,&c,1);
-        DEBUGPF("dacset");
-        (void) dac.set_dac(4,2.21);  
         humi=ain1.read();
         printf("humid %f \n ",humi);   
         */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sscm_comm.lib	Mon Oct 06 11:02:10 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wbeaumont/code/sscm_comm/#6d3c421026df