24,16 → 24,19 |
unsigned int16 timer0_overflow_count=0; |
float anemo=0; |
|
int1 barometer_present; |
|
#int_TIMER1 |
void TIMER1_isr(void) |
{ |
output_toggle(PIN_E0); |
set_timer1(0); |
|
// anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); |
// timer0_overflow_count=0; |
// set_timer0(0); |
// wind speed calculation 32.768 kHz crystal on timer1 oscilator expected. |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pulses per second calculation |
anemo = anemo / 10.5; // frequency divided by anemomether constant. |
|
timer0_overflow_count=0; |
set_timer0(0); |
set_timer1(0); |
output_toggle(PIN_E0); |
} |
|
#int_TIMER0 |
43,11 → 46,9 |
} |
|
#int_default |
default_isr() |
void default_isr() |
{ |
|
printf("Unexplained interrupt\r\n"); |
|
} |
|
void welcome(void) // Welcome message |
58,7 → 59,7 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
printf("#%s\r\n",&REV[4]); |
printf("# ver seq temp[mK] hum_temp[mK] hum[%%] "); |
printf("bar_temp[mK] pressure[hPa] Anemo[pls/s]check\r\n\r\n"); |
printf("bar_temp[mK] pressure[hPa] Anemo[m/s]check\r\n\r\n"); |
} |
|
void main() |
71,7 → 72,7 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);//|T1_CLK_OUT); |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
// setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); |
setup_timer_2(T2_DISABLED,0,1); |
setup_ccp1(CCP_OFF); |
80,18 → 81,15 |
output_high(CSN_SPI); |
|
welcome(); // welcome print and device indentification |
output_low(PIN_E1); |
|
enable_interrupts(INT_TIMER1); // interrupts used for anemometer readings |
enable_interrupts(INT_TIMER0); |
// disable_interrupts(INT_RDA); |
enable_interrupts(GLOBAL); |
output_high(PIN_E1); |
enable_interrupts(GLOBAL); |
|
restart_wdt(); //---WDT |
|
sht_init(); |
MPL_init(); // get correction coefficients from the sensor |
barometer_present = MPL_init(); // get correction coefficients from the sensor |
|
restart_wdt(); //---WDT |
|
100,7 → 98,8 |
char output[8]; // Output buffer |
int8 j; // String pointer |
int8 check=0; // Checksum is calculated between '$' and '*' |
float SHT_temp=0,SHT_hum=0; |
float SHT_temp1=0,SHT_hum1=0; |
float SHT_temp2=0,SHT_hum2=0; |
float local_temp; |
float barometer_temperature, barometer_pressure; |
|
108,11 → 107,20 |
{ // printf |
|
local_temp = ds1820_read()+27315; |
sht_rd(SHT_temp,SHT_hum); |
SHT_temp = (SHT_temp + 273.15)*100; |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
sht_rd(SHT_temp1,SHT_hum1); |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
|
if (barometer_present == TRUE) |
{ |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
} |
else |
{ |
barometer_temperature = 0; |
barometer_pressure = 0; |
} |
|
delay_us(SEND_DELAY); |
putc('$'); |
delay_us(SEND_DELAY); |
122,10 → 130,14 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%5.0f \0", local_temp ); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%5.0f \0", SHT_temp); |
sprintf(output,"%5.0f \0", SHT_temp1); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%3.1f \0", SHT_hum); |
sprintf(output,"%3.1f \0", SHT_hum1); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%5.0f \0", SHT_temp2); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%3.1f \0", SHT_hum2); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%5.0f \0", barometer_temperature); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%5.1f \0", barometer_pressure); |
136,7 → 148,7 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
delay_us(SEND_DELAY); |
} |
// output_toggle(PIN_E0); |
|
//---WDT |
restart_wdt(); |
seq++; // Increment the number of measurement |