test program to test / develop the SOLID slow control

Dependencies:   AD5384 SWSPI S25FL216K S_SCTRL_SMlib T_adt7320 adc_ad9249 sscm_comm mbed

Committer:
wbeaumont
Date:
Wed Oct 08 11:16:21 2014 +0000
Revision:
3:8b181fe62a39
Parent:
2:51bbbc3fc8c2
adc working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 0:35e1c447c9e8 1 #include "mbed.h"
wbeaumont 0:35e1c447c9e8 2 #include "mbed.h"
wbeaumont 0:35e1c447c9e8 3 #include "SWSPI.h"
wbeaumont 0:35e1c447c9e8 4 #include "SWSPI_BI.h"
wbeaumont 0:35e1c447c9e8 5 #include "S25FL216K.h"
wbeaumont 0:35e1c447c9e8 6 #include "AD5384.h"
wbeaumont 0:35e1c447c9e8 7 #include "AD9249.h"
wbeaumont 2:51bbbc3fc8c2 8 #include "adt7320.h"
wbeaumont 0:35e1c447c9e8 9 #include "S_SCTRL_SM1_PinDef.h"
wbeaumont 0:35e1c447c9e8 10 #include "S_SCTRL_SM1_hwfunct.h"
wbeaumont 0:35e1c447c9e8 11
wbeaumont 3:8b181fe62a39 12 #define VERSION "1.41"
wbeaumont 2:51bbbc3fc8c2 13
wbeaumont 0:35e1c447c9e8 14 #define DEBUGPF(x) printf((x));
wbeaumont 0:35e1c447c9e8 15 // pin function pin id
wbeaumont 0:35e1c447c9e8 16 // SPI 1
wbeaumont 0:35e1c447c9e8 17
wbeaumont 0:35e1c447c9e8 18
wbeaumont 0:35e1c447c9e8 19 S25FL216K flash(F_MOSI, F_MISO, F_SCLK,F_CS);
wbeaumont 0:35e1c447c9e8 20 Serial pc(USBTX,USBRX);
wbeaumont 0:35e1c447c9e8 21
wbeaumont 0:35e1c447c9e8 22
wbeaumont 0:35e1c447c9e8 23 char c='.';
wbeaumont 0:35e1c447c9e8 24 void callback() {
wbeaumont 0:35e1c447c9e8 25 // Note: you need to actually read from the serial to clear the RX interrupt
wbeaumont 0:35e1c447c9e8 26 c = pc.getc();
wbeaumont 0:35e1c447c9e8 27 printf("%c:",c );
wbeaumont 0:35e1c447c9e8 28 }
wbeaumont 0:35e1c447c9e8 29
wbeaumont 0:35e1c447c9e8 30
wbeaumont 0:35e1c447c9e8 31 //++++++++++++++++++++++
wbeaumont 0:35e1c447c9e8 32 int main() {
wbeaumont 2:51bbbc3fc8c2 33 bool testADC=false;
wbeaumont 2:51bbbc3fc8c2 34 bool testDAC=true;
wbeaumont 2:51bbbc3fc8c2 35 bool testTEMP=false;//true;
wbeaumont 0:35e1c447c9e8 36 pc.attach(&callback);// handles the input on the RS232 interface
wbeaumont 0:35e1c447c9e8 37 HWlines hwl ;
wbeaumont 0:35e1c447c9e8 38 assignports( &hwl );
wbeaumont 0:35e1c447c9e8 39 setdefault(hwl );
wbeaumont 0:35e1c447c9e8 40
wbeaumont 0:35e1c447c9e8 41 SWSPI spi(hwl.mosi[0],hwl.miso[0],hwl.sclk[0]); // mosi, miso, sclk
wbeaumont 0:35e1c447c9e8 42 SWSPI spi2(hwl.mosi[1],hwl.miso[1],hwl.sclk[1]); // mosi, miso, sclk
wbeaumont 0:35e1c447c9e8 43 SWSPI_BI spi_adc(hwl.msio[0],hwl.direction[0],hwl.stio_mo[0] ,hwl.sclk[0]); // msio, dir , sclk
wbeaumont 0:35e1c447c9e8 44 SWSPI_BI spi_adc2(hwl.msio[1],hwl.direction[1],hwl.stio_mo[1],hwl.sclk[1]); // msio, dir , sclk
wbeaumont 0:35e1c447c9e8 45
wbeaumont 0:35e1c447c9e8 46
wbeaumont 0:35e1c447c9e8 47 AD9249 adc[2][2]={AD9249( &spi_adc,hwl.csb1[0]), AD9249( &spi_adc,hwl.csb2[0]),
wbeaumont 0:35e1c447c9e8 48 AD9249( &spi_adc2,hwl.csb1[1]), AD9249 ( &spi_adc2,hwl.csb2[1])};
wbeaumont 0:35e1c447c9e8 49
wbeaumont 3:8b181fe62a39 50 AD5384 dac[2][1]={AD5384(&spi,hwl.dac_cs[0],hwl.dac_rst[0]), AD5384(&spi2,hwl.dac_cs[1],hwl.dac_rst[1]) };
wbeaumont 2:51bbbc3fc8c2 51 adt7320 temp[2][3]= { adt7320(&spi, hwl.t_cs[0]),adt7320(&spi, hwl.tc_cs1[0]),adt7320(&spi, hwl.tc_cs2[0]),
wbeaumont 2:51bbbc3fc8c2 52 adt7320(&spi2, hwl.t_cs[1]),adt7320(&spi2, hwl.tc_cs1[1]),adt7320(&spi2, hwl.tc_cs2[1]) };
wbeaumont 0:35e1c447c9e8 53 //float humi;
wbeaumont 0:35e1c447c9e8 54
wbeaumont 0:35e1c447c9e8 55
wbeaumont 0:35e1c447c9e8 56
wbeaumont 0:35e1c447c9e8 57 DEBUGPF("start");
wbeaumont 2:51bbbc3fc8c2 58 printf(" version %s compiled %s %s \n\r" , VERSION , __DATE__, __TIME__ );
wbeaumont 0:35e1c447c9e8 59 printf(" boardserialnr %d \n\r", get_serialnr(&hwl));
wbeaumont 0:35e1c447c9e8 60 u8 consel1=0;
wbeaumont 0:35e1c447c9e8 61 u8 consel2=1;
wbeaumont 0:35e1c447c9e8 62 u8 conls=0, conle=0; // connector select loop start , connector select loop stop
wbeaumont 0:35e1c447c9e8 63 // cc == connector counter
wbeaumont 0:35e1c447c9e8 64 if( consel1==1 && consel2== 0) { conls=0; conle=1;} // only first connector connected
wbeaumont 0:35e1c447c9e8 65 else if( consel1==0 && consel2== 1) { conls=1; conle=2;} // only second connector connected
wbeaumont 0:35e1c447c9e8 66 else if( consel1==1 && consel2== 1) { conls=0; conle=2;} //
wbeaumont 0:35e1c447c9e8 67 else { conls=0; conle=0;} // no connectors connected
wbeaumont 0:35e1c447c9e8 68 unsigned char id, grade ;
wbeaumont 0:35e1c447c9e8 69
wbeaumont 0:35e1c447c9e8 70
wbeaumont 0:35e1c447c9e8 71 /* for (u8 cc= conls; cc < conle ; cc++) {
wbeaumont 0:35e1c447c9e8 72 adc[cc][0].getDevInfo(id,grade);printf(" %d %d ",id, grade);
wbeaumont 0:35e1c447c9e8 73 adc[cc][1].getDevInfo(id,grade);printf(" %d %d ",id, grade);
wbeaumont 0:35e1c447c9e8 74
wbeaumont 0:35e1c447c9e8 75 }*/
wbeaumont 2:51bbbc3fc8c2 76 // init parts
wbeaumont 2:51bbbc3fc8c2 77 for (u8 cc= conls; cc < conle ; cc++) {
wbeaumont 3:8b181fe62a39 78 if( testDAC) { dac[cc][0].init1();
wbeaumont 2:51bbbc3fc8c2 79 }
wbeaumont 2:51bbbc3fc8c2 80 }
wbeaumont 2:51bbbc3fc8c2 81
wbeaumont 0:35e1c447c9e8 82 u32 count =0;
wbeaumont 0:35e1c447c9e8 83 while(1) {
wbeaumont 0:35e1c447c9e8 84 for (u8 cc= conls; cc < conle ; cc++) {
wbeaumont 2:51bbbc3fc8c2 85 u16 rb,rb2;
wbeaumont 2:51bbbc3fc8c2 86 if( testADC) {
wbeaumont 2:51bbbc3fc8c2 87 adc[cc][0].getDevId(id);
wbeaumont 2:51bbbc3fc8c2 88 adc[cc][0].getGrade(grade);
wbeaumont 2:51bbbc3fc8c2 89 //adc[cc][0].getDevInfo(id,grade,rb);
wbeaumont 2:51bbbc3fc8c2 90 printf("id %02X grade %02X",id, grade );
wbeaumont 2:51bbbc3fc8c2 91 printf("\n\r");
wbeaumont 2:51bbbc3fc8c2 92 adc[cc][0].setPattern1(0x1235);
wbeaumont 2:51bbbc3fc8c2 93 adc[cc][0].setPattern2(0xA5FF);
wbeaumont 2:51bbbc3fc8c2 94 adc[cc][0].readPattern1(rb);
wbeaumont 2:51bbbc3fc8c2 95 adc[cc][0].readPattern2(rb2);
wbeaumont 2:51bbbc3fc8c2 96 printf("pattern1 %04X pattern2 %04X",rb,rb2);
wbeaumont 2:51bbbc3fc8c2 97 printf("\n\r");
wbeaumont 2:51bbbc3fc8c2 98 }
wbeaumont 2:51bbbc3fc8c2 99 if( testDAC ) {
wbeaumont 2:51bbbc3fc8c2 100 u16 dataread,dr2;
wbeaumont 3:8b181fe62a39 101 u8 ch = count%39;
wbeaumont 3:8b181fe62a39 102
wbeaumont 2:51bbbc3fc8c2 103 float value=2.742; // count%16383;
wbeaumont 2:51bbbc3fc8c2 104 u16 gain=(count)%16383;//0x1235;
wbeaumont 2:51bbbc3fc8c2 105 //dataread=dac[cc].set_volt(ch,value);
wbeaumont 3:8b181fe62a39 106 dr2=dac[cc][0].set_dac(ch,gain);
wbeaumont 2:51bbbc3fc8c2 107 wait(0.001);
wbeaumont 3:8b181fe62a39 108 dataread=dac[cc][0].get_dac(ch);
wbeaumont 3:8b181fe62a39 109 printf("ch %02X dac %04X ",ch,dr2);
wbeaumont 3:8b181fe62a39 110 printf("rb %04X ",dataread);
wbeaumont 3:8b181fe62a39 111 dataread=dac[cc][0].get_offset(ch);
wbeaumont 3:8b181fe62a39 112 dr2=dac[cc][0].get_gain(ch);
wbeaumont 3:8b181fe62a39 113 printf("gain %04X ",dr2);
wbeaumont 3:8b181fe62a39 114 printf("offset %04X",dataread);
wbeaumont 3:8b181fe62a39 115 dataread=dac[cc][0].get_ctrl();
wbeaumont 2:51bbbc3fc8c2 116 printf(" cntrl %04X\n\r",dataread);
wbeaumont 2:51bbbc3fc8c2 117 }
wbeaumont 2:51bbbc3fc8c2 118 if( testTEMP) {
wbeaumont 2:51bbbc3fc8c2 119 u16 dataread ;
wbeaumont 2:51bbbc3fc8c2 120 u8 id;
wbeaumont 2:51bbbc3fc8c2 121 id=temp[cc][0].getId();
wbeaumont 2:51bbbc3fc8c2 122 dataread=temp[cc][0].get_TcritSP();
wbeaumont 2:51bbbc3fc8c2 123 printf( "temp chip ID %02X , Tcrit %04X \n\r", id, dataread);
wbeaumont 2:51bbbc3fc8c2 124 }
wbeaumont 2:51bbbc3fc8c2 125 }
wbeaumont 2:51bbbc3fc8c2 126 wait(.25);count++;
wbeaumont 0:35e1c447c9e8 127 /*
wbeaumont 2:51bbbc3fc8c2 128 flash.write(0,&c,1);
wbeaumont 0:35e1c447c9e8 129
wbeaumont 0:35e1c447c9e8 130 humi=ain1.read();
wbeaumont 0:35e1c447c9e8 131 printf("humid %f \n ",humi);
wbeaumont 0:35e1c447c9e8 132 */
wbeaumont 0:35e1c447c9e8 133 }
wbeaumont 0:35e1c447c9e8 134 }
wbeaumont 0:35e1c447c9e8 135
wbeaumont 0:35e1c447c9e8 136