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

Last change on this file since 17518 was 10910, checked in by neise, 13 years ago
File size: 4.9 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_REGS;++i) {
10 usart_write_U08_bin(adc_enables[i]);
11 usart_write_char(' ');
12 }
13 usart_write_crlf();
14 for (U08 i=0; i< VOLTAGE_REGS;++i){
15 usart_write_U08_bin(adc_channels_ready[i]);
16 usart_write_char(' ');
17 }
18 usart_write_crlf();
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_crlf();
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_crlf();
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_crlf();
51
52 usart_write_str((pU08)"ad7719 current channel:");
53 usart_write_U08(*ad7719_current_channel,2);
54 usart_write_crlf();
55
56 usart_write_str((pU08)"mux SB:");
57 usart_write_U08_hex(PORTC);
58 usart_write_str((pU08)" SA:");
59 usart_write_U08_hex(PORTA);
60 usart_write_crlf();
61*/
62}
63void print_adc_nicely() {
64 usart_write_str((pU08)"\n printing voltages in mV:\n");
65 // output: U08 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS];
66 for (U08 i=0; i< VOLTAGE_CHANNELS;++i) {
67 if (i%8 == 0) usart_write_char('\n');
68 adc_output(i, adc_values[i]);
69 usart_write_str((pU08)" ");
70 }
71 usart_write_char('\n');
72}
73
74
75void print_ad7719_nicely()
76{
77 float value;
78
79 usart_write_str((pU08)"\n printing measured resistance in kohms:\n");
80
81 for (U08 i=0; i< RESISTANCE_CHANNELS;++i) {
82 if (i%8 == 0) usart_write_char('\n');
83
84 // print channel name:
85 usart_write_str((pU08)"R:"); //R for resistance
86 usart_write_char('A'+i/8); // Letters A,B,C,D,E,F,G,H
87 //usart_write_char(' ');
88 usart_write_U08(i%8+1,1); // Numbers 1...8
89 usart_write_char(':');
90
91 // check if this channel is enabled in the bitmap
92 if (ad7719_enables[i/8] & (1<<i%8))
93 {
94 value = (6.25 * 1.024 * ad7719_values[i]) / ((U32)1 << 25);
95 usart_write_float(value, 3,6);
96 //usart_write_U32(ad7719_values[i],8);
97 //usart_write_U32_hex(data); //data
98 usart_write_str((pU08)" ");
99 } else {
100 usart_write_str((pU08)" ");
101 }
102 //usart_write_char('\n');
103 }
104}
105
106void ad7719_output(U08 channel, U32 data) {
107float value = 0;
108 usart_write_str((pU08)"R:"); //R for resistance
109 usart_write_char('A'+channel/8); // Letters A,B,C,D,E,F,G,H
110 //usart_write_char(' ');
111 usart_write_U08(channel%8+1,1); // Numbers 1...8
112 usart_write_char(':');
113
114
115 value = (6.25 * data) / ((U32)1 << 25);
116 usart_write_float(value, 3,6);
117 //usart_write_U32_hex(data); //data
118
119
120}
121
122void adc_output(U08 channel, U16 data) {
123
124// if (channel < 40)
125// usart_write_str((pU08)"V:");
126// else if (channel < 80)
127// usart_write_str((pU08)"I:");
128// else if (channel < 84)
129// usart_write_str((pU08)"H:");
130
131 if (channel <80)
132 {
133 switch ((channel%40)/4) {
134 case 0:
135 case 1:
136 usart_write_char('A');
137 break;
138 case 2:
139 case 3:
140 usart_write_char('B');
141 break;
142 case 4:
143 case 5:
144 usart_write_char('C');
145 break;
146 case 6:
147 case 7:
148 usart_write_char('D');
149 break;
150 case 8:
151 usart_write_char('E');
152 break;
153 case 9:
154 usart_write_char('F');
155 break;
156 default:
157 usart_write_char('?');
158 break;
159 }
160 }
161 else // channel 80..83
162 {
163 usart_write_char('H');
164 }
165 //usart_write_char(' ');
166
167 if ( (channel%40)/4 == 9)
168 usart_write_U08((channel)%4+1,1); // Numbers 1...4
169 else
170 usart_write_U08((channel)%8+1,1); // Numbers 1...8
171
172
173 //usart_write_U08(channel,2); // Numbers 1...8
174 usart_write_char(':');
175 usart_write_U16(data/(adc_readings_until_mean/4), 7); //data
176}
177
178
179void adc_output_all() {
180 print_adc_nicely();
181 print_ad7719_nicely();
182}
183
184
185void telegram_start(){
186 eth_write_buffer[0]='@';
187 eth_write_buffer[1]='@';
188 w5100_set_TX(eth_write_buffer, 2);
189}
190
191void print_help(){
192 usart_write_str((pU08)"printing help: -not yet- \n");
193}
194
195void print_adc_stupid() {
196 usart_write_str((pU08)"printing voltages in mV - stupid mode:\n");
197 for (U08 i = 0 ; i < VOLTAGE_CHANNELS ; ++i) {
198 usart_write_str((pU08)"ch:");
199 usart_write_U08(i,3);
200 usart_write_char(' ');
201 usart_write_U16_hex(adc_values[i]);
202 usart_write_char(' ');
203 usart_write_U16(adc_values[i],7);
204 usart_write_crlf();
205 }
206 usart_write_char('\n');
207}
Note: See TracBrowser for help on using the repository browser.