acceptable methods are possible. 3. Assume that you are using the Analog-to-Digi
ID: 3707063 • Letter: A
Question
acceptable methods are possible. 3. Assume that you are using the Analog-to-Digital (A/D) converter built into the Freedom KL46Z to monitor the battery system in a 24-volt electric wheelchair. The 24V system consists of two 12V batteries in series. In a properly working system, the voltage on each battery is the same. A mismatch of more than 0.1V indicates a potential problem. In order to read a battery voltage on the KL46Z, it is passed through a voltage divider to reduce the voltage seen by the microprocessor to a voltage below the 3.3V maximum of the microprocessor. For this application, the voltage presented to pin PTBO will be the voltage across only battery 1 divided by 6 and the voltage presented to pin PTB1 will be the total voltage of both battery 1 and battery 2, all divided by 12. For example, if battery 1 is at 12.6V and battery 2 is at 12.0V, then PTB0 will see 2.1V (i.e. 12.6/6) and PTB1 will see 2.05V (i.e. 24.6/12). You are to write a program that will sample the two voltages at PTB0 and PTB1 assuming the above configuration and report the voltages for each individual battery on the standard serial console and, further, print a warning message if the two batteries differ by 0.15V or more. The voltage output should be updated every 5 seconds.Explanation / Answer
CODING: unsigned get_port(void) { int x; static unsigned local_port; unsigned int not_ready_count,ready_count; if(local_port == 32767) return 0; if(local_port > 0) return local_port; for(x=0x200; x< 32767 && ready_count > 0) { local_port = base = x; switch_port = base + 0x18; ppi_porta = base + 0x20; ppi_portb = base + 0x21; ppi_portc = base + 0x22; return base; } } local_port = 32767; return 0; } #include #include #include #include #include #include #include extern unsigned get_port(void); main() { unsigned ADC_Chan0,dac1,eoc; int count; char data[30000]; ADC_Chan0 = get_port(); if(ADC_Chan0 == 0) { printf("no hardware found "); return; } dac1 = ADC_Chan0 + 8; eoc = ADC_Chan0 + 0x18; printf("ADC Channel 0 after get_port = %X ",ADC_Chan0); while(!kbhit()) { puts("Recording"); disable(); for(count=0; countRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.