Line 1... |
Line 1... |
1 |
#include "main.h" |
1 |
#include "main.h" |
2 |
|
2 |
|
3 |
|
3 |
|
4 |
#define LED PIN_D7 |
4 |
#define LED PIN_D7 |
5 |
|
5 |
|
6 |
#define RECORDS 100 |
6 |
#define RECORDS 1000 // length of buffer |
- |
|
7 |
#define NOISE 2 // noise treshold |
7 |
|
8 |
|
8 |
void main() |
- |
|
9 |
{ |
- |
|
10 |
|
- |
|
11 |
int16 time, time_new; |
9 |
int16 count, count_new; |
12 |
int16 log[RECORDS]; |
10 |
int16 log[RECORDS]; |
- |
|
11 |
int16 record; |
- |
|
12 |
|
- |
|
13 |
#int_RDA |
- |
|
14 |
void RDA_isr(void) // Interrupt from received character |
- |
|
15 |
{ |
13 |
int16 n; |
16 |
int16 n; |
14 |
|
17 |
|
- |
|
18 |
if(getc()=='r') // Send records |
- |
|
19 |
{ |
- |
|
20 |
printf("%Lu,", record); |
- |
|
21 |
for (n=0; n<record; n++) printf("%Lu,", log[n]); |
- |
|
22 |
printf("0\n\r"); |
- |
|
23 |
} |
- |
|
24 |
else |
- |
|
25 |
{ // Reset counters |
- |
|
26 |
set_timer0(0); |
- |
|
27 |
count = 0; |
- |
|
28 |
count_new = 0; |
- |
|
29 |
record = 0; |
- |
|
30 |
} |
- |
|
31 |
} |
- |
|
32 |
|
- |
|
33 |
|
- |
|
34 |
void main() |
- |
|
35 |
{ |
15 |
setup_adc_ports(AN0_TO_AN7|VSS_VDD); |
36 |
setup_adc_ports(AN0_TO_AN7|VSS_VDD); |
16 |
setup_adc(ADC_CLOCK_DIV_2); |
37 |
setup_adc(ADC_CLOCK_DIV_2); |
17 |
setup_psp(PSP_DISABLED); |
38 |
setup_psp(PSP_DISABLED); |
18 |
setup_spi(SPI_SS_DISABLED); |
39 |
setup_spi(SPI_SS_DISABLED); |
19 |
setup_wdt(WDT_OFF); |
40 |
setup_wdt(WDT_OFF); |
Line 23... |
Line 44... |
23 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
44 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
24 |
setup_ccp1(CCP_OFF); |
45 |
setup_ccp1(CCP_OFF); |
25 |
setup_comparator(NC_NC_NC_NC); |
46 |
setup_comparator(NC_NC_NC_NC); |
26 |
setup_vref(FALSE); |
47 |
setup_vref(FALSE); |
27 |
|
48 |
|
28 |
output_low(LED); |
49 |
output_low(LED); |
29 |
/* |
50 |
|
30 |
while(true) |
- |
|
31 |
{ |
- |
|
32 |
output_low(LED); |
51 |
enable_interrupts(INT_RDA); |
33 |
delay_ms(1); |
- |
|
34 |
output_high(LED); |
- |
|
35 |
delay_ms(1); |
- |
|
36 |
printf("%u\n\r", 0x55); |
52 |
enable_interrupts(GLOBAL); |
37 |
} |
- |
|
38 |
//*/ |
- |
|
39 |
n=0; |
53 |
record = 0; |
40 |
while(true) |
54 |
while(true) |
41 |
{ |
55 |
{ |
42 |
set_timer0(0); |
56 |
set_timer0(0); |
43 |
time = 0; |
57 |
count = 0; |
44 |
time_new = 0; |
58 |
count_new = 0; |
45 |
while(time_new == 0) |
59 |
while(count_new == 0) // waiting for a new radiation event |
46 |
{ |
60 |
{ |
47 |
time_new=get_timer0(); |
61 |
count_new=get_timer0(); |
48 |
} |
62 |
} |
49 |
output_high(LED); |
63 |
output_high(LED); |
50 |
|
64 |
|
51 |
while(time != time_new) |
65 |
while(count != count_new) // waiting for the end of radiation event |
52 |
{ |
66 |
{ |
53 |
time=time_new; |
67 |
count=count_new; |
54 |
time_new=get_timer0(); |
68 |
count_new=get_timer0(); |
55 |
delay_us(5); |
69 |
delay_us(5); |
56 |
} |
70 |
} |
57 |
|
71 |
|
58 |
if (time>3){ log[n++]=time;} |
- |
|
59 |
if (n==RECORDS) |
- |
|
60 |
{ |
- |
|
61 |
for (n=0; n<RECORDS; n++) printf("%Lu,", log[n]); |
72 |
if ((record<RECORDS)&&(count>NOISE)){ log[record++]=count;} // Record radiation event |
62 |
printf("\n\r"); |
- |
|
63 |
n = 0; |
- |
|
64 |
} |
73 |
|
65 |
output_low(LED); |
74 |
output_low(LED); |
66 |
} |
75 |
} |
67 |
|
76 |
|
68 |
} |
77 |
} |