test program to test / develop the SOLID slow control
Dependencies: AD5384 SWSPI S25FL216K S_SCTRL_SMlib T_adt7320 adc_ad9249 sscm_comm mbed
main.cpp@2:51bbbc3fc8c2, 2014-10-06 (annotated)
- Committer:
- wbeaumont
- Date:
- Mon Oct 06 11:02:10 2014 +0000
- Revision:
- 2:51bbbc3fc8c2
- Parent:
- 0:35e1c447c9e8
- Child:
- 3:8b181fe62a39
temperature added;
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:51bbbc3fc8c2 | 12 | #define VERSION "1.23" |
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 | 0:35e1c447c9e8 | 50 | AD5384 dac[2]={AD5384(&spi,hwl.dac_cs[0]), AD5384(&spi2,hwl.dac_cs[1]) }; |
wbeaumont | 0:35e1c447c9e8 | 51 | |
wbeaumont | 2:51bbbc3fc8c2 | 52 | 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 | 53 | adt7320(&spi2, hwl.t_cs[1]),adt7320(&spi2, hwl.tc_cs1[1]),adt7320(&spi2, hwl.tc_cs2[1]) }; |
wbeaumont | 0:35e1c447c9e8 | 54 | //float humi; |
wbeaumont | 0:35e1c447c9e8 | 55 | |
wbeaumont | 0:35e1c447c9e8 | 56 | |
wbeaumont | 0:35e1c447c9e8 | 57 | |
wbeaumont | 0:35e1c447c9e8 | 58 | DEBUGPF("start"); |
wbeaumont | 2:51bbbc3fc8c2 | 59 | printf(" version %s compiled %s %s \n\r" , VERSION , __DATE__, __TIME__ ); |
wbeaumont | 0:35e1c447c9e8 | 60 | printf(" boardserialnr %d \n\r", get_serialnr(&hwl)); |
wbeaumont | 0:35e1c447c9e8 | 61 | u8 consel1=0; |
wbeaumont | 0:35e1c447c9e8 | 62 | u8 consel2=1; |
wbeaumont | 0:35e1c447c9e8 | 63 | u8 conls=0, conle=0; // connector select loop start , connector select loop stop |
wbeaumont | 0:35e1c447c9e8 | 64 | // cc == connector counter |
wbeaumont | 0:35e1c447c9e8 | 65 | if( consel1==1 && consel2== 0) { conls=0; conle=1;} // only first connector connected |
wbeaumont | 0:35e1c447c9e8 | 66 | else if( consel1==0 && consel2== 1) { conls=1; conle=2;} // only second connector connected |
wbeaumont | 0:35e1c447c9e8 | 67 | else if( consel1==1 && consel2== 1) { conls=0; conle=2;} // |
wbeaumont | 0:35e1c447c9e8 | 68 | else { conls=0; conle=0;} // no connectors connected |
wbeaumont | 0:35e1c447c9e8 | 69 | unsigned char id, grade ; |
wbeaumont | 0:35e1c447c9e8 | 70 | |
wbeaumont | 0:35e1c447c9e8 | 71 | |
wbeaumont | 0:35e1c447c9e8 | 72 | /* for (u8 cc= conls; cc < conle ; cc++) { |
wbeaumont | 0:35e1c447c9e8 | 73 | adc[cc][0].getDevInfo(id,grade);printf(" %d %d ",id, grade); |
wbeaumont | 0:35e1c447c9e8 | 74 | adc[cc][1].getDevInfo(id,grade);printf(" %d %d ",id, grade); |
wbeaumont | 0:35e1c447c9e8 | 75 | |
wbeaumont | 0:35e1c447c9e8 | 76 | }*/ |
wbeaumont | 2:51bbbc3fc8c2 | 77 | // init parts |
wbeaumont | 2:51bbbc3fc8c2 | 78 | for (u8 cc= conls; cc < conle ; cc++) { |
wbeaumont | 2:51bbbc3fc8c2 | 79 | if( testDAC) { dac[cc].init1(); |
wbeaumont | 2:51bbbc3fc8c2 | 80 | } |
wbeaumont | 2:51bbbc3fc8c2 | 81 | } |
wbeaumont | 2:51bbbc3fc8c2 | 82 | |
wbeaumont | 0:35e1c447c9e8 | 83 | u32 count =0; |
wbeaumont | 0:35e1c447c9e8 | 84 | while(1) { |
wbeaumont | 0:35e1c447c9e8 | 85 | for (u8 cc= conls; cc < conle ; cc++) { |
wbeaumont | 2:51bbbc3fc8c2 | 86 | u16 rb,rb2; |
wbeaumont | 2:51bbbc3fc8c2 | 87 | if( testADC) { |
wbeaumont | 2:51bbbc3fc8c2 | 88 | adc[cc][0].getDevId(id); |
wbeaumont | 2:51bbbc3fc8c2 | 89 | adc[cc][0].getGrade(grade); |
wbeaumont | 2:51bbbc3fc8c2 | 90 | //adc[cc][0].getDevInfo(id,grade,rb); |
wbeaumont | 2:51bbbc3fc8c2 | 91 | printf("id %02X grade %02X",id, grade ); |
wbeaumont | 2:51bbbc3fc8c2 | 92 | printf("\n\r"); |
wbeaumont | 2:51bbbc3fc8c2 | 93 | adc[cc][0].setPattern1(0x1235); |
wbeaumont | 2:51bbbc3fc8c2 | 94 | adc[cc][0].setPattern2(0xA5FF); |
wbeaumont | 2:51bbbc3fc8c2 | 95 | adc[cc][0].readPattern1(rb); |
wbeaumont | 2:51bbbc3fc8c2 | 96 | adc[cc][0].readPattern2(rb2); |
wbeaumont | 2:51bbbc3fc8c2 | 97 | printf("pattern1 %04X pattern2 %04X",rb,rb2); |
wbeaumont | 2:51bbbc3fc8c2 | 98 | printf("\n\r"); |
wbeaumont | 2:51bbbc3fc8c2 | 99 | } |
wbeaumont | 2:51bbbc3fc8c2 | 100 | if( testDAC ) { |
wbeaumont | 2:51bbbc3fc8c2 | 101 | u16 dataread,dr2; |
wbeaumont | 2:51bbbc3fc8c2 | 102 | u8 ch = count%32; |
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 | 2:51bbbc3fc8c2 | 106 | dr2=dac[cc].set_dac(ch,gain); |
wbeaumont | 2:51bbbc3fc8c2 | 107 | wait(0.001); |
wbeaumont | 2:51bbbc3fc8c2 | 108 | dataread=dac[cc].get_dac(ch); |
wbeaumont | 2:51bbbc3fc8c2 | 109 | printf("ch %02X offset set to %04X ",ch,dr2); |
wbeaumont | 2:51bbbc3fc8c2 | 110 | printf("readback %04X",dataread); |
wbeaumont | 2:51bbbc3fc8c2 | 111 | dataread=dac[cc].get_ctrl(); |
wbeaumont | 2:51bbbc3fc8c2 | 112 | printf(" cntrl %04X\n\r",dataread); |
wbeaumont | 2:51bbbc3fc8c2 | 113 | } |
wbeaumont | 2:51bbbc3fc8c2 | 114 | if( testTEMP) { |
wbeaumont | 2:51bbbc3fc8c2 | 115 | u16 dataread ; |
wbeaumont | 2:51bbbc3fc8c2 | 116 | u8 id; |
wbeaumont | 2:51bbbc3fc8c2 | 117 | id=temp[cc][0].getId(); |
wbeaumont | 2:51bbbc3fc8c2 | 118 | dataread=temp[cc][0].get_TcritSP(); |
wbeaumont | 2:51bbbc3fc8c2 | 119 | printf( "temp chip ID %02X , Tcrit %04X \n\r", id, dataread); |
wbeaumont | 2:51bbbc3fc8c2 | 120 | } |
wbeaumont | 2:51bbbc3fc8c2 | 121 | } |
wbeaumont | 2:51bbbc3fc8c2 | 122 | wait(.25);count++; |
wbeaumont | 0:35e1c447c9e8 | 123 | /* |
wbeaumont | 2:51bbbc3fc8c2 | 124 | flash.write(0,&c,1); |
wbeaumont | 0:35e1c447c9e8 | 125 | |
wbeaumont | 0:35e1c447c9e8 | 126 | humi=ain1.read(); |
wbeaumont | 0:35e1c447c9e8 | 127 | printf("humid %f \n ",humi); |
wbeaumont | 0:35e1c447c9e8 | 128 | */ |
wbeaumont | 0:35e1c447c9e8 | 129 | } |
wbeaumont | 0:35e1c447c9e8 | 130 | } |
wbeaumont | 0:35e1c447c9e8 | 131 | |
wbeaumont | 0:35e1c447c9e8 | 132 |