source: firmware/FSC/usb_src/output.c@ 14065

Last change on this file since 14065 was 10244, checked in by neise, 14 years ago
debugged resistance calculation for AD7719
File size: 4.1 KB
Line 
1#include "output.h"
2#include "usart.h"
3
4void print_status() {
5 usart_write_str((pU08)"adc status:\n");
6 for (U08 i=0; i< V_BITMAP + I_BITMAP + H_BITMAP;++i) {
7 usart_write_U08_bin(adc_enables[i]);
8 usart_write_char(' ');
9 }
10 usart_write_char('\n');
11 for (U08 i=0; i< V_BITMAP + I_BITMAP + H_BITMAP;++i){
12 usart_write_U08_bin(adc_channels_ready[i]);
13 usart_write_char(' ');
14 }
15 usart_write_char('\n');
16
17 usart_write_str((pU08)"ad7719 status:\n");
18 for (U08 i=0; i< CHANNEL_BITMAP;++i) {
19 usart_write_U08_bin(ad7719_enables[i]);
20 usart_write_char(' ');
21 }
22 usart_write_char('\n');
23 for (U08 i=0; i< CHANNEL_BITMAP;++i){
24 usart_write_U08_bin(ad7719_channels_ready[i]);
25 usart_write_char(' ');
26 }
27 usart_write_char('\n');
28
29 usart_write_str((pU08)"time:");
30 usart_write_float((float)local_ms/1000 , 1,7);
31 usart_write_str((pU08)" sec.\n");
32
33 usart_write_str((pU08)"adc measured all: ");
34 if (adc_measured_all)
35 usart_write_str((pU08)" true\n");
36 else
37 usart_write_str((pU08)"false\n");
38
39 usart_write_str((pU08)"ad7719 measured all: ");
40 if (ad7719_measured_all)
41 usart_write_str((pU08)" true\n");
42 else
43 usart_write_str((pU08)"false\n");
44
45 usart_write_str((pU08)"adc current channel:");
46 usart_write_U08(adc_current_channel,2);
47 usart_write_char('\n');
48
49 usart_write_str((pU08)"ad7719 current channel:");
50 usart_write_U08(ad7719_current_channel,2);
51 usart_write_char('\n');
52
53}
54void print_adc_nicely() {
55 usart_write_str((pU08)"\n printing voltages in mV:\n");
56 // output: U08 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS];
57 for (U08 i=0; i< V_CHANNELS + I_CHANNELS + H_CHANNELS;++i) {
58 if (i%8 == 0) usart_write_char('\n');
59 adc_output(i, adc_values[i]);
60 usart_write_str((pU08)" ");
61 }
62 usart_write_char('\n');
63}
64
65
66void print_ad7719_nicely()
67{
68 float value;
69
70 usart_write_str((pU08)"\n printing measured resistance in kohms:\n");
71
72 for (U08 i=0; i< TEMP_CHANNELS;++i) {
73 if (i%8 == 0) usart_write_char('\n');
74
75 // print channel name:
76 usart_write_str((pU08)"R:"); //R for resistance
77 usart_write_char('A'+i/8); // Letters A,B,C,D,E,F,G,H
78 //usart_write_char(' ');
79 usart_write_U08(i%8+1,1); // Numbers 1...8
80 usart_write_char(':');
81
82 // check if this channel is enabled in the bitmap
83 if (ad7719_enables[i/8] & (1<<i%8))
84 {
85 value = (6.25 * 1.024 * ad7719_values[i]) / ((U32)1 << 25);
86 usart_write_float(value, 3,6);
87 //usart_write_U32(ad7719_values[i],8);
88 //usart_write_U32_hex(data); //data
89 usart_write_str((pU08)" ");
90 } else {
91 usart_write_str((pU08)" ");
92 }
93 //usart_write_char('\n');
94 }
95}
96
97void ad7719_output(U08 channel, U32 data) {
98float value = 0;
99 usart_write_str((pU08)"R:"); //R for resistance
100 usart_write_char('A'+channel/8); // Letters A,B,C,D,E,F,G,H
101 //usart_write_char(' ');
102 usart_write_U08(channel%8+1,1); // Numbers 1...8
103 usart_write_char(':');
104
105
106 value = (6.25 * data) / ((U32)1 << 25);
107 usart_write_float(value, 3,6);
108 //usart_write_U32_hex(data); //data
109
110
111}
112
113void adc_output(U08 channel, U08 data) {
114
115// if (channel < 40)
116// usart_write_str((pU08)"V:");
117// else if (channel < 80)
118// usart_write_str((pU08)"I:");
119// else if (channel < 84)
120// usart_write_str((pU08)"H:");
121
122 if (channel <80)
123 {
124 switch ((channel%40)/4) {
125 case 0:
126 case 1:
127 usart_write_char('A');
128 break;
129 case 2:
130 case 3:
131 usart_write_char('B');
132 break;
133 case 4:
134 case 5:
135 usart_write_char('C');
136 break;
137 case 6:
138 case 7:
139 usart_write_char('D');
140 break;
141 case 8:
142 usart_write_char('E');
143 break;
144 case 9:
145 usart_write_char('F');
146 break;
147 default:
148 usart_write_char('?');
149 break;
150 }
151 }
152 else // channel 80..83
153 {
154 usart_write_char('H');
155 }
156 //usart_write_char(' ');
157
158 if ( (channel%40)/4 == 9)
159 usart_write_U08((channel)%4+1,1); // Numbers 1...4
160 else
161 usart_write_U08((channel)%8+1,1); // Numbers 1...8
162
163
164 //usart_write_U08(channel,2); // Numbers 1...8
165 usart_write_char(':');
166 usart_write_U16((U16)data*16, 4); //data
167}
168
169
170void adc_output_all() {
171 print_adc_nicely();
172 print_ad7719_nicely();
173}
Note: See TracBrowser for help on using the repository browser.