![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SOLID SM1 slow control module test program
Dependencies: S_SCTRL_SMlib mbed
main.cpp@0:263895dd3670, 2014-09-07 (annotated)
- Committer:
- wbeaumont
- Date:
- Sun Sep 07 14:27:50 2014 +0000
- Revision:
- 0:263895dd3670
- Child:
- 1:39fce38f6e13
first version, no pointers tested with first board, second connector
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:263895dd3670 | 1 | #include "mbed.h" |
wbeaumont | 0:263895dd3670 | 2 | #include "S_SCTRL_SM1_PinDef.h" |
wbeaumont | 0:263895dd3670 | 3 | |
wbeaumont | 0:263895dd3670 | 4 | #define VERSION "1.28" |
wbeaumont | 0:263895dd3670 | 5 | #define RELDATE "6 Sept 2014" |
wbeaumont | 0:263895dd3670 | 6 | #define ORGANISATION "(C) Universiteit Antwerpen" |
wbeaumont | 0:263895dd3670 | 7 | #define AUTHOR "wim.beaumont@uantwerpen.be" |
wbeaumont | 0:263895dd3670 | 8 | |
wbeaumont | 0:263895dd3670 | 9 | |
wbeaumont | 0:263895dd3670 | 10 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:263895dd3670 | 11 | |
wbeaumont | 0:263895dd3670 | 12 | |
wbeaumont | 0:263895dd3670 | 13 | // devices |
wbeaumont | 0:263895dd3670 | 14 | // SPI BI pins |
wbeaumont | 0:263895dd3670 | 15 | DigitalInOut msio(ADC_STIO); |
wbeaumont | 0:263895dd3670 | 16 | DigitalOut sclk(SCLK); |
wbeaumont | 0:263895dd3670 | 17 | DigitalOut direction(DIRECTION); |
wbeaumont | 0:263895dd3670 | 18 | DigitalOut stio_mo(STIO_MO); |
wbeaumont | 0:263895dd3670 | 19 | DigitalOut csb1_1(ADC1_CSN); |
wbeaumont | 0:263895dd3670 | 20 | DigitalOut csb2_1(ADC2_CSN); |
wbeaumont | 0:263895dd3670 | 21 | |
wbeaumont | 0:263895dd3670 | 22 | |
wbeaumont | 0:263895dd3670 | 23 | |
wbeaumont | 0:263895dd3670 | 24 | // SPI pins |
wbeaumont | 0:263895dd3670 | 25 | DigitalOut mosi(MOSI); |
wbeaumont | 0:263895dd3670 | 26 | DigitalIn miso(MISO); |
wbeaumont | 0:263895dd3670 | 27 | // DigitalOut sclk(PTC16); reuse sclk |
wbeaumont | 0:263895dd3670 | 28 | DigitalOut t_cs(TEMP_CSN); |
wbeaumont | 0:263895dd3670 | 29 | DigitalOut tc_cs1(TEMP_CABLE_CSN1); |
wbeaumont | 0:263895dd3670 | 30 | DigitalOut tc_cs2(TEMP_CABLE_CSN2); |
wbeaumont | 0:263895dd3670 | 31 | DigitalOut dac_cs(DAC_DCEN); |
wbeaumont | 0:263895dd3670 | 32 | DigitalOut dac_rst(DAC_RSTN); |
wbeaumont | 0:263895dd3670 | 33 | |
wbeaumont | 0:263895dd3670 | 34 | |
wbeaumont | 0:263895dd3670 | 35 | |
wbeaumont | 0:263895dd3670 | 36 | // SPI BI 2 |
wbeaumont | 0:263895dd3670 | 37 | DigitalInOut msio2(ADC_2_STIO); |
wbeaumont | 0:263895dd3670 | 38 | DigitalOut sclk2(SCLK_2); |
wbeaumont | 0:263895dd3670 | 39 | DigitalOut direction2(DIRECTION2); |
wbeaumont | 0:263895dd3670 | 40 | DigitalOut stio_mo2(STIO2_MO); |
wbeaumont | 0:263895dd3670 | 41 | DigitalOut csb1_2(ADC1_2_CSN); |
wbeaumont | 0:263895dd3670 | 42 | DigitalOut csb2_2(ADC2_2_CSN); |
wbeaumont | 0:263895dd3670 | 43 | |
wbeaumont | 0:263895dd3670 | 44 | //SPI 2 |
wbeaumont | 0:263895dd3670 | 45 | DigitalOut mosi2(MOSI_2); |
wbeaumont | 0:263895dd3670 | 46 | DigitalIn miso2(MISO_2); |
wbeaumont | 0:263895dd3670 | 47 | DigitalOut t2_cs(TEMP_2_CSN); |
wbeaumont | 0:263895dd3670 | 48 | DigitalOut t2c_cs1(TEMP_2_CABLE_CSN1); |
wbeaumont | 0:263895dd3670 | 49 | DigitalOut t2c_cs2(TEMP_2_CABLE_CSN2); |
wbeaumont | 0:263895dd3670 | 50 | DigitalOut dac2_cs(DAC_2_DCEN); |
wbeaumont | 0:263895dd3670 | 51 | DigitalOut dac2_rst(DAC_2_RSTN); |
wbeaumont | 0:263895dd3670 | 52 | |
wbeaumont | 0:263895dd3670 | 53 | //cal |
wbeaumont | 0:263895dd3670 | 54 | DigitalOut cal13(CAL_TRIG_1AND3); |
wbeaumont | 0:263895dd3670 | 55 | DigitalOut cal24(CAL_TRIG_2AND4); |
wbeaumont | 0:263895dd3670 | 56 | DigitalOut calint(SEL_CAL_INT); |
wbeaumont | 0:263895dd3670 | 57 | DigitalOut calint2(SEL_2_CAL_INT); |
wbeaumont | 0:263895dd3670 | 58 | DigitalOut calext(SEL_CAL_EXT); |
wbeaumont | 0:263895dd3670 | 59 | DigitalOut calgenext(GEN_EXT_CAL); |
wbeaumont | 0:263895dd3670 | 60 | |
wbeaumont | 0:263895dd3670 | 61 | DigitalOut ledred(LEDRED); |
wbeaumont | 0:263895dd3670 | 62 | DigitalOut ledgreen(LEDGREEN); |
wbeaumont | 0:263895dd3670 | 63 | |
wbeaumont | 0:263895dd3670 | 64 | AnalogIn ain1(ADC1), ain2(ADC2); |
wbeaumont | 0:263895dd3670 | 65 | |
wbeaumont | 0:263895dd3670 | 66 | |
wbeaumont | 0:263895dd3670 | 67 | char c='.'; |
wbeaumont | 0:263895dd3670 | 68 | void callback() { |
wbeaumont | 0:263895dd3670 | 69 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:263895dd3670 | 70 | c = pc.getc(); |
wbeaumont | 0:263895dd3670 | 71 | //printf("%c:",c ); |
wbeaumont | 0:263895dd3670 | 72 | } |
wbeaumont | 0:263895dd3670 | 73 | |
wbeaumont | 0:263895dd3670 | 74 | |
wbeaumont | 0:263895dd3670 | 75 | |
wbeaumont | 0:263895dd3670 | 76 | void printhelp(){ |
wbeaumont | 0:263895dd3670 | 77 | printf("program to test IO lines for the Solid Slow control \n\r"); |
wbeaumont | 0:263895dd3670 | 78 | printf("version : %s\n\r%s %s \n\rAuthor %s\n\r",VERSION, ORGANISATION,RELDATE,AUTHOR ); |
wbeaumont | 0:263895dd3670 | 79 | printf("in terminal push t to see the commands\n\r"); |
wbeaumont | 0:263895dd3670 | 80 | printf("the assigned output will toggle, z will stop toggling outputs \n\r"); |
wbeaumont | 0:263895dd3670 | 81 | printf("inputs will be read each cycle, also the bi directional inputs \n\r"); |
wbeaumont | 0:263895dd3670 | 82 | printf("no protection for the directions signals (c,d,m,l) so use with care\n\r"); |
wbeaumont | 0:263895dd3670 | 83 | printf("startup values:\n\r\tmsio(2) input\n\r\tdirection(2) set to input\n\r\tstio_mo to input (adc output)\n\r"); |
wbeaumont | 0:263895dd3670 | 84 | printf("version 1.0 no io (miso only input) \n\r"); |
wbeaumont | 0:263895dd3670 | 85 | |
wbeaumont | 0:263895dd3670 | 86 | } |
wbeaumont | 0:263895dd3670 | 87 | |
wbeaumont | 0:263895dd3670 | 88 | |
wbeaumont | 0:263895dd3670 | 89 | |
wbeaumont | 0:263895dd3670 | 90 | void printcommands(int consel, DigitalOut* caldir) { |
wbeaumont | 0:263895dd3670 | 91 | int localcaldir=caldir->read(); |
wbeaumont | 0:263895dd3670 | 92 | printf("T means toggle output\n\r"); |
wbeaumont | 0:263895dd3670 | 93 | printf("connector 1 or connector 2 signal generation \n\r"); |
wbeaumont | 0:263895dd3670 | 94 | printf("a: T sclk\tb: T direction\n\r"); |
wbeaumont | 0:263895dd3670 | 95 | printf("c: T stio_mo\td: T csb1_1\n\r"); |
wbeaumont | 0:263895dd3670 | 96 | printf("e: T csb2_1\tf: T mosi\n\r"); |
wbeaumont | 0:263895dd3670 | 97 | printf("g: T t_cs\ti: T tc_cs1\n\r"); |
wbeaumont | 0:263895dd3670 | 98 | printf("h: help\n\r"); |
wbeaumont | 0:263895dd3670 | 99 | printf("j: T tc_cs2\tk: T dac_cs\n\r"); |
wbeaumont | 0:263895dd3670 | 100 | printf("l: T dac_rst\tm: T cal_13\n\r"); |
wbeaumont | 0:263895dd3670 | 101 | printf("n: T cal_24\to: T genextcal\n\r"); |
wbeaumont | 0:263895dd3670 | 102 | printf("\n\rcommon\n\r"); |
wbeaumont | 0:263895dd3670 | 103 | printf("q: sel int cal\tr: sel ext cal\n\r"); |
wbeaumont | 0:263895dd3670 | 104 | printf("s: setdefault direction, cal int \n\r"); |
wbeaumont | 0:263895dd3670 | 105 | printf("t: this table\n\r"); |
wbeaumont | 0:263895dd3670 | 106 | printf("v: version"); |
wbeaumont | 0:263895dd3670 | 107 | printf("x: sel con1\ty: sel con2\n\r"); |
wbeaumont | 0:263895dd3670 | 108 | printf("z: stop toggling\n\r"); |
wbeaumont | 0:263895dd3670 | 109 | printf("con sel=%d cal dir=%d\n\r",consel, localcaldir); |
wbeaumont | 0:263895dd3670 | 110 | |
wbeaumont | 0:263895dd3670 | 111 | } |
wbeaumont | 0:263895dd3670 | 112 | |
wbeaumont | 0:263895dd3670 | 113 | |
wbeaumont | 0:263895dd3670 | 114 | |
wbeaumont | 0:263895dd3670 | 115 | // select intern or extern cal 0 = intern, 1 is extern |
wbeaumont | 0:263895dd3670 | 116 | void setcalsource( int external) { |
wbeaumont | 0:263895dd3670 | 117 | calext=0; calint=0; calint2=0; //disable all |
wbeaumont | 0:263895dd3670 | 118 | if ( external==1 ) calext=1; |
wbeaumont | 0:263895dd3670 | 119 | else {calint=1;calint2=1; } |
wbeaumont | 0:263895dd3670 | 120 | |
wbeaumont | 0:263895dd3670 | 121 | |
wbeaumont | 0:263895dd3670 | 122 | } |
wbeaumont | 0:263895dd3670 | 123 | |
wbeaumont | 0:263895dd3670 | 124 | // set tje default , save values |
wbeaumont | 0:263895dd3670 | 125 | void setdefault( ) { |
wbeaumont | 0:263895dd3670 | 126 | msio.input(); |
wbeaumont | 0:263895dd3670 | 127 | msio2.input(); |
wbeaumont | 0:263895dd3670 | 128 | direction=LDIR_IN;direction2=LDIR_IN; |
wbeaumont | 0:263895dd3670 | 129 | stio_mo=RDIR_IN;stio_mo2=RDIR_IN; |
wbeaumont | 0:263895dd3670 | 130 | setcalsource(0); //intern |
wbeaumont | 0:263895dd3670 | 131 | } |
wbeaumont | 0:263895dd3670 | 132 | |
wbeaumont | 0:263895dd3670 | 133 | int main(){ |
wbeaumont | 0:263895dd3670 | 134 | |
wbeaumont | 0:263895dd3670 | 135 | pc.attach(&callback);// handles the input on the RS232 interface |
wbeaumont | 0:263895dd3670 | 136 | DigitalOut* dout = 0; // active signal |
wbeaumont | 0:263895dd3670 | 137 | ledred=1;ledgreen=1; |
wbeaumont | 0:263895dd3670 | 138 | int consel=1; |
wbeaumont | 0:263895dd3670 | 139 | setdefault(); |
wbeaumont | 0:263895dd3670 | 140 | printhelp(); |
wbeaumont | 0:263895dd3670 | 141 | while (true) { |
wbeaumont | 0:263895dd3670 | 142 | if( consel ==1) |
wbeaumont | 0:263895dd3670 | 143 | switch( c) { |
wbeaumont | 0:263895dd3670 | 144 | case 'a' : dout=&sclk; break; |
wbeaumont | 0:263895dd3670 | 145 | case 'b' : dout=&direction; break; |
wbeaumont | 0:263895dd3670 | 146 | case 'c' : dout=&stio_mo; break; |
wbeaumont | 0:263895dd3670 | 147 | case 'd' : dout=&csb1_1; break; |
wbeaumont | 0:263895dd3670 | 148 | case 'e' : dout=&csb2_1; break; |
wbeaumont | 0:263895dd3670 | 149 | case 'f' : dout=&mosi; break; |
wbeaumont | 0:263895dd3670 | 150 | case 'g' : dout=&t_cs; break; |
wbeaumont | 0:263895dd3670 | 151 | case 'i' : dout=&tc_cs1; break; |
wbeaumont | 0:263895dd3670 | 152 | case 'j' : dout=&tc_cs2; break; |
wbeaumont | 0:263895dd3670 | 153 | case 'k' : dout=&dac_cs; break; |
wbeaumont | 0:263895dd3670 | 154 | case 'l' : dout=&dac_rst; break; |
wbeaumont | 0:263895dd3670 | 155 | case 'm' : dout=&cal13; break; |
wbeaumont | 0:263895dd3670 | 156 | case 'n' : dout=&cal24; break; |
wbeaumont | 0:263895dd3670 | 157 | case 'o' : dout=&calgenext; break; |
wbeaumont | 0:263895dd3670 | 158 | default : break; |
wbeaumont | 0:263895dd3670 | 159 | |
wbeaumont | 0:263895dd3670 | 160 | |
wbeaumont | 0:263895dd3670 | 161 | |
wbeaumont | 0:263895dd3670 | 162 | |
wbeaumont | 0:263895dd3670 | 163 | } |
wbeaumont | 0:263895dd3670 | 164 | if( consel ==2) |
wbeaumont | 0:263895dd3670 | 165 | switch( c) { |
wbeaumont | 0:263895dd3670 | 166 | case 'a' : dout=&sclk2; break; |
wbeaumont | 0:263895dd3670 | 167 | case 'b' : dout=&direction2; break; |
wbeaumont | 0:263895dd3670 | 168 | case 'c' : dout=&stio_mo2; break; |
wbeaumont | 0:263895dd3670 | 169 | case 'd' : dout=&csb1_2; break; |
wbeaumont | 0:263895dd3670 | 170 | case 'e' : dout=&csb2_2; break; |
wbeaumont | 0:263895dd3670 | 171 | case 'f' : dout=&mosi2; break; |
wbeaumont | 0:263895dd3670 | 172 | case 'g' : dout=&t2_cs; break; |
wbeaumont | 0:263895dd3670 | 173 | case 'i' : dout=&t2c_cs1; break; |
wbeaumont | 0:263895dd3670 | 174 | case 'j' : dout=&t2c_cs2; break; |
wbeaumont | 0:263895dd3670 | 175 | case 'k' : dout=&dac2_cs; break; |
wbeaumont | 0:263895dd3670 | 176 | case 'l' : dout=&dac2_rst; break; |
wbeaumont | 0:263895dd3670 | 177 | case 'm' : dout=&cal13; break; |
wbeaumont | 0:263895dd3670 | 178 | case 'n' : dout=&cal24; break; |
wbeaumont | 0:263895dd3670 | 179 | case 'o' : dout=&calgenext; break; |
wbeaumont | 0:263895dd3670 | 180 | default : break; |
wbeaumont | 0:263895dd3670 | 181 | } |
wbeaumont | 0:263895dd3670 | 182 | |
wbeaumont | 0:263895dd3670 | 183 | |
wbeaumont | 0:263895dd3670 | 184 | //common |
wbeaumont | 0:263895dd3670 | 185 | switch( c) { |
wbeaumont | 0:263895dd3670 | 186 | case 'h' : printhelp();wait(5); |
wbeaumont | 0:263895dd3670 | 187 | case 'q' : setcalsource(0); break; |
wbeaumont | 0:263895dd3670 | 188 | case 'r' : setcalsource(1); break; |
wbeaumont | 0:263895dd3670 | 189 | case 's' : setdefault(); break; |
wbeaumont | 0:263895dd3670 | 190 | case 't' : printcommands(consel, &calint); wait(5);break; |
wbeaumont | 0:263895dd3670 | 191 | case 'v' : printf ("version %s comiled at %s %s\n\r" , VERSION,__DATE__,__TIME__); |
wbeaumont | 0:263895dd3670 | 192 | wait(2); |
wbeaumont | 0:263895dd3670 | 193 | break; |
wbeaumont | 0:263895dd3670 | 194 | case 'x' : consel=1;break; |
wbeaumont | 0:263895dd3670 | 195 | case 'y' : consel=2;break; |
wbeaumont | 0:263895dd3670 | 196 | case 'z' : dout=NULL; break; |
wbeaumont | 0:263895dd3670 | 197 | |
wbeaumont | 0:263895dd3670 | 198 | default : break; |
wbeaumont | 0:263895dd3670 | 199 | }; |
wbeaumont | 0:263895dd3670 | 200 | c='.';// reset input to default |
wbeaumont | 0:263895dd3670 | 201 | if ( dout != NULL ) { |
wbeaumont | 0:263895dd3670 | 202 | *dout = !(*dout); // toggle pin ; |
wbeaumont | 0:263895dd3670 | 203 | //ledgreen!=ledgreen; |
wbeaumont | 0:263895dd3670 | 204 | } |
wbeaumont | 0:263895dd3670 | 205 | //ledred!=ledred; |
wbeaumont | 0:263895dd3670 | 206 | printf( "miso1:%d msio1:%d miso2:%d msio:%d adc1:%f adc2:%f\n\r", |
wbeaumont | 0:263895dd3670 | 207 | miso.read(),msio.read(), miso2.read(),miso2.read(),ain1.read(),ain2.read() ); |
wbeaumont | 0:263895dd3670 | 208 | |
wbeaumont | 0:263895dd3670 | 209 | wait(0.5f); |
wbeaumont | 0:263895dd3670 | 210 | } |
wbeaumont | 0:263895dd3670 | 211 | } |