Changeset 10106 for firmware/FSC
- Timestamp:
- 01/15/11 12:42:22 (14 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/FSC.c
r10102 r10106 60 60 BOOL heartbeat_enable = TRUE; 61 61 62 U08 SA_mux_val = 0x 00;62 U08 SA_mux_val = 0x16; 63 63 U08 SB_mux_val = 0x00; 64 64 65 65 //U08 counter = 0; 66 66 U08 Res_or_Volt = 0x00; 67 67 68 68 … … 72 72 // measure with a scope. 73 73 if (heartbeat_enable) PORTB ^= (1<<PB3); // toggle Out2_spare --> heartbeat 74 //adc_init(); 75 76 77 78 _delay_ms(1); 79 /* 74 adc_init(); 75 76 ++Res_or_Volt; 77 if (Res_or_Volt <= 64){ 80 78 81 79 … … 87 85 // by setting the usart_rx_ready flag FALSE again 88 86 ++SA_mux_val; 89 if (SA_mux_val == 64) SA_mux_val = 0; 87 if (Res_or_Volt == 1) SB_mux_val = 16; 88 else if (SA_mux_val == 64) SA_mux_val = 32; 89 else if (SA_mux_val == 16) SA_mux_val = 48; 90 else if (SA_mux_val == 32) SA_mux_val = 0; 90 91 PORTA = (SA_mux_val & 0x3F); 91 92 92 usart_write_str((pU08)"SA:");93 // usart_write_str((pU08)"SA:"); 93 94 usart_write_U08(SA_mux_val,2); 94 95 usart_write_str((pU08)" Sensor:"); … … 116 117 break; 117 118 } 118 usart_write_str((pU08)"\n"); 119 _delay_us(200); 119 // usart_write_str((pU08)"\n"); 120 usart_write_str((pU08)" "); 121 122 123 startconv(); 124 120 125 121 122 123 124 for (U08 counter = 0; counter < 10; ++counter) {125 126 127 126 while (!ADC_IS_READY()) 128 127 { 129 128 // just wait until ADC is redy -- really bad code here! 130 129 } 131 startconv(); //Start a new A/D Conversion 130 131 resistance = getresistance(); 132 //Start a new A/D Conversion 133 //temp = readandsendtemp(); 134 //adcword = getadc(); 135 136 //temperature = gettemp(); 137 usart_write_str((pU08)"R:"); 138 usart_write_float(resistance,3,4); 139 usart_write_str((pU08)"kOhm "); 140 141 //_delay_ms(200); 142 143 startconv(); 144 145 while (!ADC_IS_READY()) 146 { 147 // just wait until ADC is redy -- really bad code here! 148 } 149 //Start a new A/D Conversion 132 150 //temp = readandsendtemp(); 133 151 //adcword = getadc(); … … 136 154 usart_write_str((pU08)"R:"); 137 155 usart_write_float(resistance,3,4); 138 usart_write_str((pU08)"kOhm "); 139 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 usart_write_str((pU08)"kOhm "); 157 158 //usart_write_str((pU08)"\n"); 159 switch (SA_mux_val) 160 { 161 case 7: usart_write_str((pU08)"\n\n"); 162 break; 163 case 15: usart_write_str((pU08)"\n\n"); 164 break; 165 case 23: usart_write_str((pU08)"\n\n"); 166 break; 167 case 31: usart_write_str((pU08)"\n\n"); 168 break; 169 case 39: usart_write_str((pU08)"\n\n"); 170 break; 171 case 47: usart_write_str((pU08)"\n\n"); 172 break; 173 case 55: usart_write_str((pU08)"\n\n"); 174 break; 175 case 63: usart_write_str((pU08)"\n\n"); 176 break; 177 default: usart_write_str((pU08)"\n"); 178 break; 179 } 180 SB_mux_val = 0; 156 181 } 157 usart_write_str((pU08)"\n\n\n"); 158 */ 159 160 ++SB_mux_val; 182 else if (Res_or_Volt == 148) Res_or_Volt = 0; 183 else { 184 185 186 ++SB_mux_val; 161 187 if (SB_mux_val == 84) SB_mux_val = 0; 162 PORTC = (SB_mux_val & 0x7F); 163 164 _delay_ms(5); 188 else if (SB_mux_val == 74) SB_mux_val = 82; 189 else if (SB_mux_val == 82) SB_mux_val = 72; 190 else if (SB_mux_val == 72) SB_mux_val = 74; 191 else if (SB_mux_val == 48) SB_mux_val = 64; 192 else if (SB_mux_val == 64) SB_mux_val = 32; 193 else if (SB_mux_val == 32) SB_mux_val = 48; 194 PORTC = (SB_mux_val & 0x7F); 195 196 165 197 166 198 … … 211 243 if (SB_mux_val % 2 == 0) { 212 244 usart_write_str((pU08)"U"); 213 usart_write_U08( ( SB_mux_val%8)/2 , 1 );245 usart_write_U08( ((SB_mux_val-2)%8)/2 , 1 ); 214 246 } else { 215 247 usart_write_str((pU08)"I"); 216 usart_write_U08( (( SB_mux_val%8)-1)/2 , 1 );248 usart_write_U08( (((SB_mux_val-2)%8)-1)/2 , 1 ); 217 249 } 218 250 … … 222 254 } 223 255 224 for (U08 counter = 0; counter < 10; ++counter) { 256 for (U08 counter = 0; counter < 1; ++counter) { 257 ADCSRA |= (1<<ADSC); 225 258 while (ADCSRA & (1<<ADSC) ); // wait until internal ADC is ready 226 ADCSRA |= (1<<ADSC);227 259 float voltage; 228 260 voltage = ( (float)ADCH ) / 256 * 4.096; … … 231 263 232 264 233 _delay_ms(300);234 265 } 235 usart_write_str((pU08)"\n"); 236 237 266 //usart_write_str((pU08)"\n"); 267 268 switch (SB_mux_val) 269 { 270 case 15: usart_write_str((pU08)"\n\n"); 271 break; 272 case 31: usart_write_str((pU08)"\n\n"); 273 break; 274 case 47: usart_write_str((pU08)"\n\n"); 275 break; 276 case 63: usart_write_str((pU08)"\n\n"); 277 break; 278 case 71: usart_write_str((pU08)"\n\n"); 279 break; 280 case 73: usart_write_str((pU08)"\n\n"); 281 break; 282 case 81: usart_write_str((pU08)"\n\n"); 283 break; 284 case 83: usart_write_str((pU08)"\n\n"); 285 break; 286 default: usart_write_str((pU08)"\n"); 287 break; 288 } 289 290 SA_mux_val = 15; 291 } 238 292 /* 239 293 if ( usart_rx_ready == TRUE ) -
firmware/FSC/src/ad7719_adc.c
r10102 r10106 107 107 U8 COM = 0x01; 108 108 U8 SERIAL = 0x02; 109 110 111 112 113 114 115 116 109 CLR_BIT(PORTD,SPI_AD_CS); // Set CS low 110 spi_transfer_byte(COM); // Next Operation is write to Mode Register 111 spi_transfer_byte(SERIAL); // Start new A/D conversion 112 SET_BIT(PORTD,SPI_AD_CS); 113 COM = 0x45; 114 CLR_BIT(PORTD,SPI_AD_CS); // Set CS low 115 spi_transfer_byte(COM); // Next Operation is read from Main ADC Data Register 116 SET_BIT(PORTD,SPI_AD_CS); // Set CS high 117 117 } 118 118
Note:
See TracChangeset
for help on using the changeset viewer.