Hallo, ich lasse geade eine Atmel Studio 6 ATtiny13A Simulation laufen und ich drehe langsam durch.... Das Prgramm überspringt immer die unten im code mit "#!#" makierten Zeilen! ( #!# sind nicht im Code vorhanden) Ich bekomme es nicht hin, dass die ausgeführt werden. Schritt für schritt ausführen springt immer über die beiden zeilen und durchlaufen lassen zeigt auch keine wirkung. Wisst ihr was da los ist? LG, Florian
1 | uint16_t readVccVoltage(void) { |
2 | // Returns the current Vcc voltage as a fixed point number with 3 implied decimal places, i.e.
|
3 | // 5000 = 5.000 volts, 2500 = 2.500 volts, 1900 = 1.900 volts
|
4 | |
5 | V_DEV_ON; //turning on the voltage divider by setting PB0 low |
6 | |
7 | // Select ADC input PB2 and 1.1V (Internal Ref)
|
8 | ADMUX = (1<<REFS0)|(1<<MUX0); |
9 | |
10 | // Enable ADC, set prescaller to /8 which will give a ADC clock of 1.2Mhz/8 = 150kHz
|
11 | ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0) ; |
12 | |
13 | _delay_ms(1); |
14 | |
15 | ADCSRA |= (1<<ADSC); // Start a conversion |
16 | while( ADCSRA & (1<<ADSC) ) ; // Wait for 1st conversion to be ready... |
17 | //..and ignore the result
|
18 | uint8_t dummy = ADCH; |
19 | |
20 | ADCSRA |= (1<<ADSC); // Start a conversion |
21 | while( ADCSRA & (1<<ADSC) ) ; // Wait for conversion to be ready... |
22 | V_DEV_OFF; // turning PB0 high to save voltage at the voltage divider |
23 | |
24 | uint8_t low = ADCL; |
25 | uint8_t high = ADCH; |
26 | |
27 | #!# uint16_t adcVal = (high << 8) | low; // 0<= result <=1023
|
28 | |
29 | #!# uint16_t Vin = (uint16_t)((uint16_t)4100*adcVal)/1000;
|
30 | |
31 | ADCSRA &= ~(1<<ADEN ); // Disable ADC to save power |
32 | return(Vin); |
33 | }
|