source: firmware/FSC/src/output.c@ 10902

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