/Designs/Data_loggers/GPSRL04C/SW/PIC/Spectrometer/main.c
3,15 → 3,36
 
#define LED PIN_D7
 
#define RECORDS 100
#define RECORDS 1000 // length of buffer
#define NOISE 2 // noise treshold
 
void main()
int16 count, count_new;
int16 log[RECORDS];
int16 record;
 
#int_RDA
void RDA_isr(void) // Interrupt from received character
{
 
int16 time, time_new;
int16 log[RECORDS];
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);
26,42 → 47,30
setup_vref(FALSE);
 
output_low(LED);
/*
 
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
record = 0;
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);
time = 0;
time_new = 0;
while(time_new == 0)
count = 0;
count_new = 0;
while(count_new == 0) // waiting for a new radiation event
{
time_new=get_timer0();
count_new=get_timer0();
}
output_high(LED);
while(time != time_new)
while(count != count_new) // waiting for the end of radiation event
{
time=time_new;
time_new=get_timer0();
count=count_new;
count_new=get_timer0();
delay_us(5);
}
if (time>3){ log[n++]=time;}
if (n==RECORDS)
{
for (n=0; n<RECORDS; n++) printf("%Lu,", log[n]);
printf("\n\r");
n = 0;
}
if ((record<RECORDS)&&(count>NOISE)){ log[record++]=count;} // Record radiation event
 
output_low(LED);
}