Changeset 10697 for firmware/FSC/src/FSC_eth_with_user_interface.c
- Timestamp:
- 05/13/11 11:48:49 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/FSC_eth_with_user_interface.c
r10677 r10697 21 21 bool heartbeat_enable; 22 22 23 // AD7719 global variables 24 U32 ad7719_values[RESISTANCE_CHANNELS]; 25 U08 ad7719_enables[RESISTANCE_CHANNELS/8]; 26 U08 ad7719_channels_ready[RESISTANCE_CHANNELS/8]; 27 U08 ad7719_readings_since_last_muxing = 0; 28 U08 ad7719_current_channel = 0; 29 U32 ad7719_current_reading = 0; 23 30 24 bool ad7719_measured_all = false; 31 25 bool ad7719_values_printed = true; … … 33 27 34 28 // ATMEGA ADC global variables 35 U08 adc_readings_until_mean=250; 36 U32 adc_values[VOLTAGE_CHANNELS]; // stores measured voltage in steps of 16mV 37 U08 adc_enables[VOLTAGE_CHANNELS/8]; 38 U08 adc_channels_ready[VOLTAGE_CHANNELS/8]; 39 U08 adc_readings_since_last_muxing = 0; 40 U08 adc_current_channel = 0; 41 U16 adc_current_reading = 0; 29 42 30 bool adc_measured_all = false; 43 31 bool adc_values_printed = true; … … 53 41 // M A I N --- M A I N --- M A I N --- M A I N --- M A I N 54 42 //----------------------------------------------------------------------------- 55 /*56 int main(void)57 {58 59 60 U16 received_bytes;61 U08 really_downloaded_bytes;62 while(!usart_rx_ready){63 received_bytes = get_S0_RX_RSR();64 65 66 67 68 if (get_S0_RX_RSR() != 0) { // we have something to read69 usart_write_str((pU08)"\nReading ");70 usart_write_U16(get_S0_RX_RSR(), 6);71 usart_write_str((pU08)" b from W5100\n");72 73 while (received_bytes != 0) {74 really_downloaded_bytes = w5100_get_RX(16, true);75 usart_write_char('!');76 usart_write_U08(really_downloaded_bytes,4);77 usart_write_char('\n');78 for (U08 i=0; i<really_downloaded_bytes; i++){79 usart_write_U08_hex(eth_read_buffer[i]);80 usart_write_char(' ');81 }82 received_bytes -= really_downloaded_bytes;83 }84 }85 usart_write_char('\n');86 87 _delay_ms(400);88 _delay_ms(400);89 _delay_ms(400);90 _delay_ms(400);91 }92 usart_rx_ready = false;93 94 bool quit = false;95 while (!quit) {96 usart_write_str((pU08)"Enter the string to send to PC or \"XXX\" in order to quit\n");97 while(!usart_rx_ready){98 _delay_ms(100);99 }100 usart_rx_ready = false;101 102 if ( (usart_rx_buffer[0]=='X') && (usart_rx_buffer[1]=='X') && (usart_rx_buffer[2]=='X') )103 quit = true;104 else {105 // copy string to W5100 TX buffer and issue 'SEND' command.106 for (U08 i =0; i<usart_received_chars; i++){107 eth_write_buffer[i]=usart_rx_buffer[i];108 }109 110 w5100_set_TX(usart_received_chars);111 112 }113 114 115 }116 117 } // end of main()118 */119 43 int main(void) 120 44 { … … 123 47 spi_init(); // Initialize SPI interface as master 124 48 timer_init(); // set up TIMER2: TIMER2_COMP interrupt occurs every 1ms 125 49 atmega_adc_init(); 50 126 51 w5100_reset(); 127 52 w5100_init(); 128 53 54 ad7719_init(); 55 129 56 // Enable interrupts 130 57 sei(); … … 167 94 if (get_S0_RX_RSR() != 0) { // we have something to read 168 95 downloaded_bytes = w5100_get_RX(ETH_READ_BUFFER_SIZE, true); 169 usart_write_str((pU08)"got ethernet stream - no. of. bytes:"); 170 usart_write_U08(downloaded_bytes,3); 171 usart_write_char('\n'); 172 for (U08 i=0; i<downloaded_bytes; i++){ 173 usart_write_U08_hex(eth_read_buffer[i]); 174 usart_write_char(' '); 175 } 176 usart_write_char('\n'); 177 } 178 } 179 180 //---------------------------------------------------------------------------- 96 parse_w5300_incoming( downloaded_bytes ); 97 } 98 } 99 100 //---------------------------------------------------------------------------- 101 181 102 if (check_if_adc_measurement_done()) { 103 telegram_start(); 104 w5100_set_TX(adc_values, ADC_VALUES_LEN_BYTE); 105 182 106 if(adc_print_endless){ 183 107 usart_write_str((pU08)"V|"); 184 108 usart_write_U32(sec ,8); 185 109 print_adc_nicely(false,true); 186 for ( U08 i=0; i<(VOLTAGE_CHANNELS/8); ++i ) { 187 adc_channels_ready[i]=0; 188 } 110 reset_voltage_done(); 189 111 } else 190 112 if ( !adc_values_printed) { … … 195 117 196 118 if (check_if_ad7719_measurement_done()) { 119 telegram_start(); 120 w5100_set_TX(ad7719_values, AD7719_VALUES_LEN_BYTE); 121 197 122 if(ad7719_print_endless){ 198 123 usart_write_str((pU08)"R|"); 199 124 usart_write_U32(sec ,8); 200 125 print_ad7719_nicely(false,true); 201 for ( U08 i=0; i<(RESISTANCE_CHANNELS/8); ++i ) { 202 ad7719_channels_ready[i]=0; 203 } 126 reset_resistance_done(); 204 127 } else 205 128 if ( !ad7719_values_printed) { … … 261 184 //IF ATmega internal ADC did finish a conversion --every 200us 262 185 if ( (ADCSRA & (1<<ADIF)) && !adc_measured_all) { 263 adc_current_reading = (U16)ADCL;264 adc_current_reading += (U16)ADCH<<8;265 if ( adc_readings_since_last_muxing == ADC_READINGS_UNTIL_SETTLED+adc_readings_until_mean-1) {266 adc_channels_ready[ adc_current_channel/8] |= (1<<(adc_current_channel%8));267 adc_current_channel = increase_adc (adc_current_channel);268 adc_values[ adc_current_channel] = 0;269 Set_V_Muxer( adc_current_channel);270 adc_readings_since_last_muxing = 0;186 *adc_current_reading = (U16)ADCL; 187 *adc_current_reading += (U16)ADCH<<8; 188 if (*adc_readings_since_last_muxing == ADC_READINGS_UNTIL_SETTLED+adc_readings_until_mean-1) { 189 adc_channels_ready[*adc_current_channel/8] |= (1<<(*adc_current_channel%8)); 190 *adc_current_channel = increase_adc (*adc_current_channel); 191 adc_values[*adc_current_channel] = 0; 192 Set_V_Muxer(*adc_current_channel); 193 *adc_readings_since_last_muxing = 0; 271 194 _delay_ms(10); 272 195 } 273 196 else if (adc_readings_since_last_muxing >= ADC_READINGS_UNTIL_SETTLED-1) { 274 adc_values[ adc_current_channel] +=adc_current_reading;275 ++ adc_readings_since_last_muxing;197 adc_values[*adc_current_channel] += *adc_current_reading; 198 ++(*adc_readings_since_last_muxing); 276 199 } 277 200 else { 278 ++ adc_readings_since_last_muxing;201 ++(*adc_readings_since_last_muxing); 279 202 } 280 203 … … 285 208 286 209 if (AD7719_IS_READY() && !ad7719_measured_all) { 287 ad7719_current_reading = read_adc(); // --takes at 4MHz SCLK speed about 6us210 *ad7719_current_reading = read_adc(); // --takes at 4MHz SCLK speed about 6us 288 211 // AD7719 is only read out if settled. saves time. 289 if ( ad7719_readings_since_last_muxing == AD7719_READINGS_UNTIL_SETTLED-1) {290 ad7719_values[ ad7719_current_channel] =ad7719_current_reading;291 ad7719_readings_since_last_muxing=0;212 if (*ad7719_readings_since_last_muxing == AD7719_READINGS_UNTIL_SETTLED-1) { 213 ad7719_values[*ad7719_current_channel] = *ad7719_current_reading; 214 *ad7719_readings_since_last_muxing=0; 292 215 if (debug_mode) { 293 usart_write_U32_hex( ad7719_current_reading);216 usart_write_U32_hex(*ad7719_current_reading); 294 217 usart_write_char('\n'); 295 218 usart_write_char('\n'); … … 299 222 // note that this channel is ready, now and 300 223 // proceed to the next enabled channel. 301 ad7719_channels_ready[ ad7719_current_channel/8] |= (1<<(ad7719_current_channel%8));302 ad7719_current_channel = increase_ad7719 (ad7719_current_channel);303 Set_T_Muxer( ad7719_current_channel);224 ad7719_channels_ready[*ad7719_current_channel/8] |= (1<<(*ad7719_current_channel%8)); 225 *ad7719_current_channel = increase_ad7719 (*ad7719_current_channel); 226 Set_T_Muxer(*ad7719_current_channel); 304 227 } else { // the AD7719 did not settle yet, we discard the reading 305 ++ ad7719_readings_since_last_muxing;228 ++(*ad7719_readings_since_last_muxing); 306 229 if (debug_mode) { 307 usart_write_U32_hex( ad7719_current_reading);230 usart_write_U32_hex(*ad7719_current_reading); 308 231 usart_write_char('\n'); 309 232 }
Note:
See TracChangeset
for help on using the changeset viewer.