3,36 → 3,15 |
|
#define LED PIN_D7 |
|
#define RECORDS 1000 // length of buffer |
#define NOISE 2 // noise treshold |
#define RECORDS 100 |
|
int16 count, count_new; |
void main() |
{ |
|
int16 time, time_new; |
int16 log[RECORDS]; |
int16 record; |
|
#int_RDA |
void RDA_isr(void) // Interrupt from received character |
{ |
int16 n; |
|
if(getc()=='r') // Send records |
{ |
printf("%Lu,", record); |
for (n=0; n<record; n++) printf("%Lu,", log[n]); |
printf("0\n\r"); |
} |
else |
{ // Reset counters |
set_timer0(0); |
count = 0; |
count_new = 0; |
record = 0; |
} |
} |
|
|
void main() |
{ |
setup_adc_ports(AN0_TO_AN7|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_psp(PSP_DISABLED); |
46,31 → 25,43 |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
|
output_low(LED); |
|
enable_interrupts(INT_RDA); |
enable_interrupts(GLOBAL); |
record = 0; |
output_low(LED); |
/* |
while(true) |
{ |
output_low(LED); |
delay_ms(1); |
output_high(LED); |
delay_ms(1); |
printf("%u\n\r", 0x55); |
} |
//*/ |
n=0; |
while(true) |
{ |
set_timer0(0); |
count = 0; |
count_new = 0; |
while(count_new == 0) // waiting for a new radiation event |
time = 0; |
time_new = 0; |
while(time_new == 0) |
{ |
count_new=get_timer0(); |
time_new=get_timer0(); |
} |
output_high(LED); |
|
while(count != count_new) // waiting for the end of radiation event |
while(time != time_new) |
{ |
count=count_new; |
count_new=get_timer0(); |
time=time_new; |
time_new=get_timer0(); |
delay_us(5); |
} |
|
if ((record<RECORDS)&&(count>NOISE)){ log[record++]=count;} // Record radiation event |
|
if (time>3){ log[n++]=time;} |
if (n==RECORDS) |
{ |
for (n=0; n<RECORDS; n++) printf("%Lu,", log[n]); |
printf("\n\r"); |
n = 0; |
} |
output_low(LED); |
} |
|