Changeset 10102 for firmware/FSC
- Timestamp:
- 01/14/11 07:46:11 (14 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/FSC.c
r10094 r10102 21 21 22 22 spare_outs_init(); //set spare out pin I/O modes 23 app_init(); // Setup software modules24 usart_init(); // Initialize serial interface23 app_init(); // Setup software modules 24 usart_init(); // Initialize serial interface 25 25 spi_init(); // Initialize SPI interface as master 26 26 adc_init(); // Initialize AD7719 ADC as SPI slave … … 40 40 // voltage, current, humidity - muxer pins: 41 41 // SB - pins 42 DDR B|= 0x7F; // set all SB - pins as outputs42 DDRC |= 0x7F; // set all SB - pins as outputs 43 43 44 44 // SB - muxer test 45 DDRA |= 1<<PA6 ; // set D0-0 lina as output. for tests only !!! 46 PORTA |= 1<<PA6; // set D0-0 line high. for tests only !!! 45 // DDRA |= 1<<PA6 ; // set D0-0 lina as output. for tests only !!! 46 // PORTA |= 1<<PA6; // set D0-0 line high. for tests only !!! 47 DDRA &= ~(1<<PA6); 48 49 //ADC einschalten 50 ADMUX = 0x26; //0010.0110 // interne Referenzspannung nutzen 51 ADCSRA = (1<<ADPS1) | (1<<ADPS0); // Frequenzvorteiler 52 ADCSRA |= (1<<ADEN); // ADC aktivieren 53 ADCSRA |= (1<<ADSC); 47 54 48 55 … … 53 60 BOOL heartbeat_enable = TRUE; 54 61 55 U08 SA_mux_val = 0; 56 //U08 SB_mx_val = 0; 62 U08 SA_mux_val = 0x00; 63 U08 SB_mux_val = 0x00; 64 65 //U08 counter = 0; 66 67 68 57 69 while (TRUE) 58 70 { … … 60 72 // measure with a scope. 61 73 if (heartbeat_enable) PORTB ^= (1<<PB3); // toggle Out2_spare --> heartbeat 74 //adc_init(); 75 76 77 78 _delay_ms(1); 79 /* 80 62 81 63 82 // if USART data arrives. i.e. data via USB … … 68 87 // by setting the usart_rx_ready flag FALSE again 69 88 ++SA_mux_val; 70 PORTA |= (SA_mux_val & 0x3F); 89 if (SA_mux_val == 64) SA_mux_val = 0; 90 PORTA = (SA_mux_val & 0x3F); 91 92 usart_write_str((pU08)"SA:"); 93 usart_write_U08(SA_mux_val,2); 94 usart_write_str((pU08)" Sensor:"); 95 usart_write_U08((SA_mux_val % 8)+1,2); 96 usart_write_str((pU08)" an Temperatur_"); 97 switch (SA_mux_val / 8) 98 { 99 case 0: usart_write_str((pU08)"C"); 100 break; 101 case 1: usart_write_str((pU08)"D"); 102 break; 103 case 2: usart_write_str((pU08)"A"); 104 break; 105 case 3: usart_write_str((pU08)"B"); 106 break; 107 case 4: usart_write_str((pU08)"G"); 108 break; 109 case 5: usart_write_str((pU08)"H"); 110 break; 111 case 6: usart_write_str((pU08)"E"); 112 break; 113 case 7: usart_write_str((pU08)"F"); 114 break; 115 default: usart_write_str((pU08)"alarm!"); 116 break; 117 } 118 usart_write_str((pU08)"\n"); 119 _delay_us(200); 120 121 122 123 124 for (U08 counter = 0; counter < 10; ++counter) { 125 71 126 72 usart_write_str((pU08)"\tSA:"); 73 usart_write_U08(SA_mux_val,2); 74 usart_write_str((pU08)"\t"); 75 _delay_us(200); 127 while (!ADC_IS_READY()) 128 { 129 // just wait until ADC is redy -- really bad code here! 130 } 131 startconv(); //Start a new A/D Conversion 132 //temp = readandsendtemp(); 133 //adcword = getadc(); 134 resistance = getresistance(); 135 //temperature = gettemp(); 136 usart_write_str((pU08)"R:"); 137 usart_write_float(resistance,3,4); 138 usart_write_str((pU08)"kOhm "); 76 139 77 78 if(ADC_IS_READY()) 79 { 80 startconv(); //Start a new A/D Conversion 81 //temp = readandsendtemp(); 82 //adcword = getadc(); 83 resistance = getresistance(); 84 //temperature = gettemp(); 85 usart_write_str((pU08)"R:"); 86 usart_write_float(resistance,3,4); 87 usart_write_str((pU08)"\t"); 88 } 89 if(ADC_IS_READY()) 90 { 91 startconv(); //Start a new A/D Conversion 92 //temp = readandsendtemp(); 93 //adcword = getadc(); 94 resistance = getresistance(); 95 //temperature = gettemp(); 96 usart_write_str((pU08)"R:"); 97 usart_write_float(resistance,3,4); 98 usart_write_str((pU08)"\n"); 99 } 140 141 while (!ADC_IS_READY()) 142 { 143 // just wait until ADC is redy -- really bad code here! 144 } 145 146 startconv(); //Start a new A/D Conversion 147 //temp = readandsendtemp(); 148 //adcword = getadc(); 149 resistance = getresistance(); 150 //temperature = gettemp(); 151 usart_write_str((pU08)"R:"); 152 usart_write_float(resistance,3,4); 153 usart_write_str((pU08)"kOhm\n"); 154 155 _delay_ms(500); 156 } 157 usart_write_str((pU08)"\n\n\n"); 158 */ 159 160 ++SB_mux_val; 161 if (SB_mux_val == 84) SB_mux_val = 0; 162 PORTC = (SB_mux_val & 0x7F); 163 164 _delay_ms(5); 165 166 167 usart_write_str((pU08)"8bit-ADC: "); 168 169 if (SB_mux_val < 64) 170 { 171 switch (SB_mux_val / 16) 172 { 173 case 0: usart_write_str((pU08)"voltage_A: "); 174 break; 175 case 1: usart_write_str((pU08)"voltage_B: "); 176 break; 177 case 2: usart_write_str((pU08)"voltage_D: "); 178 break; 179 case 3: usart_write_str((pU08)"voltage_C: "); 180 break; 181 } 182 183 if (SB_mux_val % 2 == 0) { 184 usart_write_str((pU08)"U"); 185 usart_write_U08( (SB_mux_val%16)/2 , 1 ); 186 } else { 187 usart_write_str((pU08)"I"); 188 usart_write_U08( ((SB_mux_val%16)-1)/2 , 1 ); 189 } 190 191 192 } else { 193 194 195 if (SB_mux_val < 72) { 196 usart_write_str((pU08)"voltage_E: "); 197 if (SB_mux_val % 2 == 0) { 198 usart_write_str((pU08)"U"); 199 usart_write_U08( (SB_mux_val%8)/2 , 1 ); 200 } else { 201 usart_write_str((pU08)"I"); 202 usart_write_U08( ((SB_mux_val%8)-1)/2 , 1 ); 203 } 204 205 } 206 else if (SB_mux_val == 72) usart_write_str((pU08)"humidity_A: H0"); 207 else if (SB_mux_val == 73) usart_write_str((pU08)"humidity_A: H1"); 208 209 else if (SB_mux_val < 82) { 210 usart_write_str((pU08)"voltage_F: "); 211 if (SB_mux_val % 2 == 0) { 212 usart_write_str((pU08)"U"); 213 usart_write_U08( (SB_mux_val%8)/2 , 1 ); 214 } else { 215 usart_write_str((pU08)"I"); 216 usart_write_U08( ((SB_mux_val%8)-1)/2 , 1 ); 217 } 218 219 } 220 else if (SB_mux_val == 82) usart_write_str((pU08)"humidity_B: H0"); 221 else if (SB_mux_val == 83) usart_write_str((pU08)"humidity_B: H1"); 222 } 223 224 for (U08 counter = 0; counter < 10; ++counter) { 225 while (ADCSRA & (1<<ADSC) ); // wait until internal ADC is ready 226 ADCSRA |= (1<<ADSC); 227 float voltage; 228 voltage = ( (float)ADCH ) / 256 * 4.096; 229 usart_write_str((pU08)" "); 230 usart_write_float(voltage,3,4); 231 232 233 _delay_ms(300); 234 } 235 usart_write_str((pU08)"\n"); 100 236 101 237 -
firmware/FSC/src/ad7719_adc.c
r10094 r10102 51 51 const U8 WR_TO_AD0CON = 0x02; 52 52 const U8 WR_TO_MODE = 0x01; 53 const U8 RD_FROM_FILTER = 0x44; 54 55 CLR_BIT(PORTD,SPI_AD_CS); // Set CS low 56 spi_transfer_byte(RD_FROM_FILTER); // Next Operation is write to IOCON1 and IOCON2 Start SPI 57 spi_transfer_byte(0xFF); // Next Operation is write to IOCON1 and IOCON2 Start SPI 58 SET_BIT(PORTD,SPI_AD_CS); // Set CS high 59 60 61 53 62 54 63 CLR_BIT(PORTD,SPI_AD_CS); // Set CS low -
firmware/FSC/src/ad7719_adc.h
r10094 r10102 10 10 #define ADC_RDY PD6 11 11 #define ADC_RST PD7 12 #define ADC_IS_READY() !(PIND & PD6) // TRUE if PD6=0 AD_RDY is inverted logic.12 #define ADC_IS_READY() !(PIND & (1<<PD6)) // TRUE if PD6=0 AD_RDY is inverted logic. 13 13 14 14 // Port Definitions -
firmware/FSC/src/application.h
r10094 r10102 28 28 #define USART_RX_BUFFER_SIZE 64 // Receive buffer size 29 29 30 #define USART_BAUDRATE 38400 // USART baudrate original30 #define USART_BAUDRATE 9600 // USART baudrate original 31 31 32 32 #define USART_USE_TX // Transmitter used? -
firmware/FSC/src/interpol.c
r10094 r10102 289 289 U32 adcword=0; 290 290 float resistance; 291 const float R_REF=6.2 8; // kilo-ohms291 const float R_REF=6.25; // kilo-ohms 292 292 adcword = read_adc(); 293 293 U32 fullscale = 16777215L; //2^24 -1 -
firmware/FSC/src/spi_master.c
r10094 r10102 37 37 SPI_PRT |= (1 << SPI_MOSI); 38 38 SPI_PRT |= (1 << SPI_SCLK); 39 //SPI_PRT |= (1 << SPI_MISO);39 SPI_PRT |= (1 << SPI_MISO); 40 40 41 41 … … 221 221 { 222 222 // Start SPI Transfer 223 if (!(SPCR & (1<<MSTR)) ) 224 SPCR |= 1<<MSTR; 223 225 SPDR = data; 224 226 -
firmware/FSC/src/spi_master.h
r10094 r10102 17 17 #define SPI_MISO PB6 18 18 // #define SPI_SS PB4 // not in this application!!! danger 19 #define SPI_E_CS P D2//device 019 #define SPI_E_CS PB4 //device 0 20 20 #define SPI_AD_CS PD3 //device 1 21 21 #define SPI_M_CS PD4 //device 2
Note:
See TracChangeset
for help on using the changeset viewer.