Problem with comparison.
/Modules/TDC/GP201A/SW/PICinterface/GP2.c
0,0 → 1,247
 
//struct {
unsigned int8 firenum=TDC_FIRENUM_0;
unsigned int8 div_fire=TDC_DIV_FIRE_2;
unsigned int8 calresnum=TDC_CALPERIODS_2;
unsigned int8 clkhsdiv=TDC_CLKHSDIV_1;
unsigned int8 start_clkhs=TDC_CLKHS_ON;
unsigned int1 portnum=TDC_TPORTNUM_4;
unsigned int1 Tcycle=TDC_TCYCLE_SHORT;
unsigned int1 fakenum=TDC_TFAKENUM_2;
unsigned int1 selclkT=TDC_TSELCLK_128HS;
unsigned int1 calibrate=TDC_CALIBRATE_EN;
unsigned int1 disautocal=TDC_AUTOCAL_EN;
unsigned int1 MRange=TDC_MRANGE2;
unsigned int1 neg_stop2=TDC_NEG_STOP2;
unsigned int1 neg_stop1=TDC_NEG_STOP1;
unsigned int1 neg_start=TDC_NEG_START;
//}reg0;
 
//struct {
unsigned int hit2=TDC_MRANGE1_HIT2_NOAC;
unsigned int hit1=TDC_MRANGE1_HIT1_NOAC;
unsigned int1 fast_init=TDC_FAST_INIT_DIS;
unsigned int hitin2=TDC_HITIN2_0;
unsigned int hitin1=TDC_HITIN1_0;
//}reg1;
 
//struct {
unsigned int en_int=TDC_INT_ALU;
unsigned int1 rfedge2=TDC_CH2EDGE_RIS;
unsigned int1 rfedge1=TDC_CH1EDGE_RIS;
unsigned int32 delval1=0;
//}reg2;
 
//struct {
unsigned int1 en_err_val=TDC_ERRVAL_DIS;
unsigned int tim0_mr2=TDC_TIM0MR2_16384CLKHS;
unsigned int32 delval2=0;
//}reg3;
 
//reg4
unsigned int32 delval3=0;
 
//reg5
unsigned int conf_fire=0;
unsigned int1 en_startnoise=TDC_STARTNOISE_DIS;
unsigned int1 dis_phasenoise=TDC_PHASENOISE_DIS;
unsigned int repeat_fire=TDC_REPEAT_FIRE_0;
unsigned int16 phase_fire=0;
 
//}TDC_registers;
 
 
void TDC_init()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x70,8);
output_high(TDC_ENABLE);
}
 
void TDC_reset()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x50,8);
output_high(TDC_ENABLE);
}
 
void TDC_start_cycle()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x01,8);
output_high(TDC_ENABLE);
}
 
void TDC_start_temp()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x02,8);
output_high(TDC_ENABLE);
}
 
void TDC_start_cal_resonator()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x03,8);
output_high(TDC_ENABLE);
}
 
void TDC_start_cal()
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x04,8);
output_high(TDC_ENABLE);
}
 
unsigned int32 TDC_get_measurement(int num)
{
unsigned int32 ret;
 
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0xB0 + num, 8);
ret=spi_xfer(TDC_stream,0,32);
output_high(TDC_ENABLE);
return ret;
}
 
unsigned int16 TDC_get_status()
{
unsigned int16 ret;
 
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0xB4,8);
ret=spi_xfer(TDC_stream,0,16);
output_high(TDC_ENABLE);
return ret;
}
 
unsigned int8 TDC_get_reg1()
{
unsigned int8 ret;
 
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0xB5,8);
ret=spi_xfer(TDC_stream,0,8);
output_high(TDC_ENABLE);
return ret;
}
 
void TDC_update_reg1() // updates reg1 only
{
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x81,8);
spi_xfer(TDC_stream,hit2,4);
spi_xfer(TDC_stream,hit1,4);
spi_xfer(TDC_stream,fast_init,1);
spi_xfer(TDC_stream,1,1);
spi_xfer(TDC_stream,hitin2,3);
spi_xfer(TDC_stream,hitin1,3);
spi_xfer(TDC_stream,0,8);
output_high(TDC_ENABLE);
}
 
void TDC_update_registers()
{
//update reg0
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x80,8);
spi_xfer(TDC_stream,firenum,4);
spi_xfer(TDC_stream,div_fire,4);
spi_xfer(TDC_stream,calresnum,2);
spi_xfer(TDC_stream,clkhsdiv,2);
spi_xfer(TDC_stream,start_clkhs,2);
spi_xfer(TDC_stream,portnum,1);
spi_xfer(TDC_stream,Tcycle,1);
spi_xfer(TDC_stream,fakenum,1);
spi_xfer(TDC_stream,selclkT,1);
spi_xfer(TDC_stream,calibrate,1);
spi_xfer(TDC_stream,disautocal,1);
spi_xfer(TDC_stream,MRange,1);
spi_xfer(TDC_stream,neg_stop2,1);
spi_xfer(TDC_stream,neg_stop1,1);
spi_xfer(TDC_stream,neg_start,1);
output_high(TDC_ENABLE);
 
TDC_update_reg1(); // update reg1
 
// update reg2
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x82);
spi_xfer(TDC_stream,en_int,3);
spi_xfer(TDC_stream,rfedge2,1);
spi_xfer(TDC_stream,rfedge1,1);
spi_xfer(TDC_stream,delval1,19);
output_high(TDC_ENABLE);
 
// update reg3
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x83);
spi_xfer(TDC_stream,0,2);
spi_xfer(TDC_stream,en_err_val,1);
spi_xfer(TDC_stream,tim0_mr2,2);
spi_xfer(TDC_stream,delval2,19);
output_high(TDC_ENABLE);
 
// update reg4
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x84);
spi_xfer(TDC_stream,0b00100,5);
spi_xfer(TDC_stream,delval3,19);
output_high(TDC_ENABLE);
 
// update reg5
output_low(TDC_ENABLE);
spi_xfer(TDC_stream,0x85);
spi_xfer(TDC_stream,conf_fire,3);
spi_xfer(TDC_stream,en_startnoise,1);
spi_xfer(TDC_stream,dis_phasenoise,1);
spi_xfer(TDC_stream,repeat_fire,3);
spi_xfer(TDC_stream,phase_fire,16);
output_high(TDC_ENABLE);
}
 
float TDC_mrange2_get_time(unsigned int shot)
{
unsigned int32 measurement;
float time;
 
switch (shot)
{
case 1:
hit2=TDC_MRANGE2_HIT2_1CH1;
break;
 
case 2:
hit2=TDC_MRANGE2_HIT2_2CH1;
break;
 
case 3:
hit2=TDC_MRANGE2_HIT2_3CH1;
break;
}
TDC_update_reg1(); // tell to ALU which shot period must be computed
Delay_ms(50); // wait to computing of result
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address
 
switch (clkhsdiv)
{
case TDC_CLKHSDIV_1:
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS;
break;
 
case TDC_CLKHSDIV_2:
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 2.0;
break;
 
case TDC_CLKHSDIV_4:
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 4.0;
break;
case TDC_CLKHSDIV_8:
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 8.0;
break;
}
return time;
}
/Modules/TDC/GP201A/SW/PICinterface/GP2.h
0,0 → 1,154
 
 
#define TDC_CLKHS 5000000 // frequency of highspeed oscillator
 
//register 0
#define TDC_NEG_START_INV 1
#define TDC_NEG_START 0
#define TDC_NEG_STOP1_INV 1
#define TDC_NEG_STOP1 0
#define TDC_NEG_STOP2_INV 1
#define TDC_NEG_STOP2 0
#define TDC_MRANGE1 0
#define TDC_MRANGE2 1
#define TDC_AUTOCAL_EN 0
#define TDC_AUTOCAL_DIS 1
#define TDC_CALIBRATE_EN 1
#define TDC_CALIBRATE_DIS 0
#define TDC_TSELCLK_32KHZ 0
#define TDC_TSELCLK_128HS 1
#define TDC_TFAKENUM_2 0
#define TDC_TFAKENUM_8 1
#define TDC_TCYCLE_SHORT 0
#define TDC_TCYSLE_LONG 1
#define TDC_TPORTNUM_2 0
#define TDC_TPORTNUM_4 1
#define TDC_CLKHS_OFF 0
#define TDC_CLKHS_ON 1
#define TDC_CLKHS_640US 2
#define TDC_CLKHS_1280US 4
#define TDC_CLKHSDIV_1 0
#define TDC_CLKHSDIV_2 1
#define TDC_CLKHSDIV_4 2
#define TDC_CLKHSDIV_8 3
#define TDC_CALPERIODS_2 0
#define TDC_CALPERIODS_4 1
#define TDC_CALPERIODS_8 2
#define TDC_CALPERIODS_16 3
 
#define TDC_DIV_FIRE_2 1
#define TDC_DIV_FIRE_3 2
#define TDC_DIV_FIRE_4 3
#define TDC_DIV_FIRE_5 4
#define TDC_DIV_FIRE_6 5
#define TDC_DIV_FIRE_7 6
#define TDC_DIV_FIRE_8 7
#define TDC_DIV_FIRE_9 8
#define TDC_DIV_FIRE_10 9
#define TDC_DIV_FIRE_11 10
#define TDC_DIV_FIRE_12 11
#define TDC_DIV_FIRE_13 12
#define TDC_DIV_FIRE_14 13
#define TDC_DIV_FIRE_15 14
#define TDC_DIV_FIRE_16 15
 
#define TDC_FIRENUM_0 0
#define TDC_FIRENUM_1 1
#define TDC_FIRENUM_2 2
#define TDC_FIRENUM_3 3
#define TDC_FIRENUM_4 4
#define TDC_FIRENUM_5 5
#define TDC_FIRENUM_6 6
#define TDC_FIRENUM_7 7
#define TDC_FIRENUM_8 8
#define TDC_FIRENUM_9 9
#define TDC_FIRENUM_10 10
#define TDC_FIRENUM_11 11
#define TDC_FIRENUM_12 12
#define TDC_FIRENUM_13 13
#define TDC_FIRENUM_14 14
#define TDC_FIRENUM_15 15
 
//register 1
#define TDC_HITIN1_0 0
#define TDC_HITIN1_1 1
#define TDC_HITIN1_2 2
#define TDC_HITIN1_3 3
#define TDC_HITIN1_4 4
 
#define TDC_HITIN2_0 0
#define TDC_HITIN2_1 1
#define TDC_HITIN2_2 2
#define TDC_HITIN2_3 3
#define TDC_HITIN2_4 4
 
#define TDC_FAST_INIT_EN 1
#define TDC_FAST_INIT_DIS 0
 
#define TDC_MRANGE1_HIT1_START 0
#define TDC_MRANGE1_HIT1_1CH1 1
#define TDC_MRANGE1_HIT1_2CH1 2
#define TDC_MRANGE1_HIT1_3CH1 3
#define TDC_MRANGE1_HIT1_4CH1 4
#define TDC_MRANGE1_HIT1_NOAC 5
#define TDC_MRANGE1_HIT1_CAL1CH1 6
#define TDC_MRANGE1_HIT1_CAL2CH1 7
#define TDC_MRANGE1_HIT1_1CH2 9
#define TDC_MRANGE1_HIT1_2CH2 0xA
#define TDC_MRANGE1_HIT1_3CH2 0xB
#define TDC_MRANGE1_HIT1_4CH2 0xC
 
#define TDC_MRANGE2_HIT1_START 1
 
#define TDC_MRANGE1_HIT2_START 0
#define TDC_MRANGE1_HIT2_1CH1 1
#define TDC_MRANGE1_HIT2_2CH1 2
#define TDC_MRANGE1_HIT2_3CH1 3
#define TDC_MRANGE1_HIT2_4CH1 4
#define TDC_MRANGE1_HIT2_NOAC 5
#define TDC_MRANGE1_HIT2_CAL1CH1 6
#define TDC_MRANGE1_HIT2_CAL2CH1 7
#define TDC_MRANGE1_HIT2_1CH2 9
#define TDC_MRANGE1_HIT2_2CH2 0xA
#define TDC_MRANGE1_HIT2_3CH2 0xB
#define TDC_MRANGE1_HIT2_4CH2 0xC
 
#define TDC_MRANGE2_HIT2_1CH1 2
#define TDC_MRANGE2_HIT2_2CH1 3
#define TDC_MRANGE2_HIT2_3CH1 4
 
//register 2
#define TDC_INT_TIMEOUT 4
#define TDC_INT_ENDHIT 2
#define TDC_INT_ALU 1
#define TDC_CH1EDGE_RIS 0
#define TDC_CH1EDGE_FAL 1
#define TDC_CH2EDGE_RIS 0
#define TDC_CH2EDGE_FAL 1
 
//register 3
#define TDC_TIM0MR2_256CLKHS 0
#define TDC_TIM0MR2_1024CLKHS 1
#define TDC_TIM0MR2_4096CLKHS 2
#define TDC_TIM0MR2_16384CLKHS 3
 
#define TDC_ERRVAL_EN 1
#define TDC_ERRVAL_DIS 0
 
//register 5
#define TDC_REPEAT_FIRE_0 0
#define TDC_REPEAT_FIRE_1 1
#define TDC_REPEAT_FIRE_2 2
#define TDC_REPEAT_FIRE_3 3
#define TDC_REPEAT_FIRE_4 4
#define TDC_REPEAT_FIRE_5 5
#define TDC_REPEAT_FIRE_6 6
#define TDC_REPEAT_FIRE_7 7
 
#define TDC_PHASENOISE_EN 0
#define TDC_PHASENOISE_DIS 1
 
#define TDC_STARTNOISE_EN 1
#define TDC_STARTNOISE_DIS 0
 
#include "GP2.c"
/Modules/TDC/GP201A/SW/PICinterface/main.c
0,0 → 1,129
#include "main.h"
 
#define VERSION 0.2
 
#define START PIN_D4
#define STOP1 PIN_D5
#define STOP2 PIN_D6
 
#include "GP2.h"
 
#define ONE_WIRE_PIN PIN_E2
#include "ds1820.c"
 
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
TDC_reset();
 
output_low(START);
output_low(STOP1);
output_low(STOP2);
 
delay_ms(50);
 
/*
1 0 0 0 0 ADR2 ADR1 ADR0 Write into address ADR
1 0 1 1 0 ADR2 ADR1 ADR0 Read from address ADR
0 1 1 1 0 0 0 0 Init
0 1 0 1 0 0 0 0 Power On Reset
0 0 0 0 0 0 0 1 Start_Cycle
0 0 0 0 0 0 1 0 Start_Temp
0 0 0 0 0 0 1 1 Start_Cal_Resonator
0 0 0 0 0 1 0 0 Start_Cal_TDC
*/
 
int16 ret16;
int8 ret8;
 
 
while(TRUE)
{
delay_ms(100);
TDC_reset();
delay_ms(100);
//----------------------------------------------- Nastaveni registru
hit1=TDC_MRANGE2_HIT1_START;
hitin1=TDC_HITIN1_4;
hitin2=TDC_HITIN2_0;
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
en_err_val=TDC_ERRVAL_EN;
delval1=0x0;
delval2=0x0;
delval3=0x0;
TDC_update_registers();
 
//----------------------------------------------- Vypis registru
printf("- %LX %LX %LX %LX ", TDC_get_measurement(0), TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3));
output_low(TDC_ENABLE);
ret8=0;
ret8=(0b1011<<4)|4;
spi_xfer(TDC_stream,ret8,8);
ret16=spi_xfer(TDC_stream,0,16);
output_high(TDC_ENABLE);
printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&ret16);
printf("%X\r\n",TDC_get_reg1());
//----------------------------------------------- Mereni
TDC_init();
delay_ms(50);
TDC_start_cycle();
delay_ms(200);
output_high(STOP2); // Merime jenom jednim kanalem (druhy zrejme musi byt v H)
output_high(START);
output_low(START);
delay_us(15);
output_high(STOP1);
output_low(STOP1);
delay_us(1);
output_high(STOP1);
output_low(STOP1);
delay_us(10);
output_high(STOP1);
output_low(STOP1);
delay_us(1);
//----------------------------------------------- Pocitani
 
printf(" %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
output_low(TDC_ENABLE); //status register
ret8=0;
ret8=(0b1011<<4)|4;
spi_xfer(TDC_stream,ret8,8);
ret16=spi_xfer(TDC_stream,0,16);
output_high(TDC_ENABLE);
printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
printf("%X\r\n",TDC_get_reg1());
}
}
/Modules/TDC/GP201A/SW/PICinterface/main.hex
0,0 → 1,344
:1000000021EF07F04150200807E0426E3D363E36B2
:100010003F364036422EFAD79382939093948A9437
:1000200041C042F08A8440AE8A9040BE8A803D360C
:100030003E363F3640368A94003601360236033665
:1000400081A2009081B20080422EECD7000C9396E2
:100050008A96406A3F6A3E6A500E3D6E080E416EB7
:10006000D1DF93968A86000CEA6A350EE96EEF506E
:100070000DE0060E016E006A002EFED7012EFBD7A2
:100080007B0E006E002EFED7EF2EF3D7000C93965A
:100090008A96406A3F6A3E6A810E3D6E080E416E46
:1000A000B1DF406A3F6A3E6A0BC03DF0040E416E0C
:1000B000A9DF406A3F6A3E6A0CC03DF0040E416E03
:1000C000A1DF000E0AB4010E406A3F6A3E6A3D6E2F
:1000D000010E416E97DF406A3F6A3E6A010E3D6E37
:1000E000416E90DF406A3F6A3E6A0DC03DF0030EEC
:1000F000416E88DF406A3F6A3E6A0EC03DF0030EE3
:10010000416E80DF406A3F6A3E6A3D6A080E416E7A
:1001100079DF93968A86000C93968A96406A3F6AA6
:100120003E6A800E3D6E080E416E6CDF406A3F6A8B
:100130003E6A04C03DF0040E416E64DF406A3F6ACF
:100140003E6A05C03DF0040E416E5CDF406A3F6AC6
:100150003E6A06C03DF0020E416E54DF406A3F6ABF
:100160003E6A07C03DF0020E416E4CDF406A3F6AB6
:100170003E6A08C03DF0020E416E44DF000E09B039
:10018000010E406A3F6A3E6A3D6E010E416E3ADFE3
:10019000000E09B2010E406A3F6A3E6A3D6E010ED2
:1001A000416E30DF000E09B4010E406A3F6A3E6ABC
:1001B0003D6E010E416E26DF000E09B6010E406A4B
:1001C0003F6A3E6A3D6E010E416E1CDF000E09B8AB
:1001D000010E406A3F6A3E6A3D6E010E416E12DFBB
:1001E000000E09BA010E406A3F6A3E6A3D6E010E7A
:1001F000416E08DF000E09BC010E406A3F6A3E6A8C
:100200003D6E010E416EFEDE000E09BE010E406A1B
:100210003F6A3E6A3D6E010E416EF4DE000E0AB08A
:10022000010E406A3F6A3E6A3D6E010E416EEADE93
:10023000000E0AB2010E406A3F6A3E6A3D6E010E30
:10024000416EE0DE93968A8622DF93968A96406A14
:100250003F6A3E6A820E3D6E200E416ED3DE406ADA
:100260003F6A3E6A0FC03DF0030E416ECBDE000ECA
:100270000AB6010E406A3F6A3E6A3D6E010E416E4B
:10028000C1DE000E0AB8010E406A3F6A3E6A3D6E4A
:10029000010E416EB7DE13C040F012C03FF011C036
:1002A0003EF010C03DF0130E416EACDE93968A8690
:1002B00093968A96406A3F6A3E6A830E3D6E200E90
:1002C000416EA0DE406A3F6A3E6A3D6A020E416EA0
:1002D00099DE000E0ABA010E406A3F6A3E6A3D6E20
:1002E000010E416E8FDE406A3F6A3E6A14C03DF0E7
:1002F000020E416E87DE18C040F017C03FF016C0F6
:100300003EF015C03DF0130E416E7CDE93968A865A
:1003100093968A96406A3F6A3E6A840E3D6E200E2E
:10032000416E70DE406A3F6A3E6A040E3D6E050E05
:10033000416E68DE1CC040F01BC03FF01AC03EF0AA
:1003400019C03DF0130E416E5DDE93968A8693963A
:100350008A96406A3F6A3E6A850E3D6E200E416E67
:1003600051DE406A3F6A3E6A1DC03DF0030E416E99
:1003700049DE000E0ABC010E406A3F6A3E6A3D6ECD
:10038000010E416E3FDE000E0ABE010E406A3F6A5A
:100390003E6A3D6E010E416E35DE406A3F6A3E6A3E
:1003A0001EC03DF0030E416E2DDE406A3F6A20C044
:1003B0003EF01FC03DF0100E416E24DE93968A86FB
:1003C000B6EF07F093968A96B00E37243C6E406ADB
:1003D0003F6A3E6A3D6E080E416E14DE406A3F6A17
:1003E0003E6A3D6A200E416E0DDE015003C03BF0B7
:1003F00002C03AF001C039F000C038F093968A8606
:1004000038C000F039C001F03AC002F03BC003F040
:10041000000C939E8A9E080E016E00D00000018E93
:100420000ED0019E3D32D8B08A8ED8A08A9E018C13
:1004300006D0019C012EF6D700D000008A8EA70EB0
:10044000E96EE92EFED700D001BEEBD701BCF1D793
:10045000000C35BE0FD00F0E006E343800160A0E99
:10046000005C03E2300E002602D03550002600C0AA
:100470003DF0CFDF0F0E34160A0E345C02E2300E70
:1004800002D0359E3550342634C03DF0C2DF000C1A
:10049000EACF3AF0E9CF39F03338F009356E352636
:1004A000E20F366E320F386E33500F0B362636267B
:1004B0003826E90F376E3726372632380F0B3726A6
:1004C000382637363836381E383632500F0B382635
:1004D0003536070E346E0A0E37063826FDE336062B
:1004E0003726FDE335063626FDE334063526FDE3E3
:1004F000EA6A340EE96E070E3914399CE926380E83
:10050000E95CD8B4398CEF50006E08E139BC06D0F4
:1005100039B813D039B602D0200E03D039863998B5
:10052000300E0026EACF33F0E9CF32F000C03DF0C4
:1005300070DF33C0EAFF32C0E9FFEE5039ACDFD7DD
:10054000000C93968A96406A3F6A3E6AB50E3D6EED
:10055000080E416E57DD406A3F6A3E6A3D6A080EEA
:10056000416E50DD015000C024F093968A8624C06D
:1005700001F0000C93968A96406A3F6A3E6A700EBC
:100580003D6E080E416E3EDD93968A8635EF09F08A
:1005900093968A96406A3F6A3E6A010E3D6E080E47
:1005A000416E30DD93968A863BEF09F093968A96EA
:1005B000406A3F6A3E6AB40E3D6E080E416E22DD0F
:1005C000406A3F6A3E6A3D6A100E416E1BDD015073
:1005D00001C036F000C035F093968A8635C001F030
:1005E00036C002F0000CB60E006E036A026A016AA1
:1005F000355036103710381002E1006A0DD0D8900F
:1006000001BE09D03536363637363836033602362F
:100610000136002EF4D7019E000C3950D8B4A5D075
:10062000456E3D50D8B4A1D0455E05E37F0E45260A
:10063000D8B09BD006D0810E455ED8A096D0D8B455
:1006400094D045C000F0016A026A036A446A3AC065
:1006500043F0438E3BC042F03CC041F0190E456E62
:100660004050415E0DE2010E425E0AE2435E08E246
:10067000445E06E2442A432A422A4050412628D0BA
:100680003F50425E12E2010E435E0FE2445E0DE215
:10069000442A432A3F5042264050412619E3422A29
:1006A00017E1432A15E1442A13D03E508009435EE6
:1006B0000EE2010E445E0BE2442A3E5080094326BE
:1006C0003F504226E9E3432AE7E1442AE5D7038085
:1006D000452E01D00BD0D8904136423643364436B1
:1006E000D8900336023601364636BAD746A006D031
:1006F000D890013202320332463202D0000635E091
:1007000046BE1ED0D890413642364336443640501D
:10071000415E07E2010E425E04E2435E02E2445E95
:100720001AE33F50425E05E2010E435E02E2445E80
:1007300012E33E508009435E03E2010E445E0BE388
:10074000032A09E1022A07E1012A05E1002A0DE056
:100750000132023203323AC045F03E50451A45AEEE
:1007600002D0018E06D0019E04D0006A016A026A9E
:10077000036A000C3D50D8B471D0006E4150D8B41B
:100780006DD0002604E3810E002668E204D07F0EBF
:10079000005E64E363E03EC045F04250451A3E8E81
:1007A000428E40504402F4CF47F03F504302F4CF12
:1007B00003F0F3CF46F04402F3504726F4504622AC
:1007C000000E032240504302F3504726F4504622C5
:1007D000000E026A032202223E504402F3504626D3
:1007E000F4500322000E02223E504302F35003262F
:1007F000F4500222000E016A012240504202F350DE
:100800004626F4500322000E022201223F504202EB
:10081000F3500326F4500222000E01223E50420201
:10082000F3500226F4500122002A01BE05D04636BC
:100830000336023601360006000E46AE0AD0032A01
:1008400002220122015005E1025003E1035001E1BF
:10085000002A45BE018E45AE019E04D0006A016AA1
:10086000026A036A000C2C50010A05E0030A06E044
:10087000010A07E009D0020E0B6E06D0030E0B6EC4
:1008800003D0040E0B6E00D002DC320E356E34EC59
:1008900000F08CDE02C003F00150070B356E366AA3
:1008A000376E90DD03C030F002C02FF001C02EF093
:1008B00000C02DF00750FC0FD8B089D1040FF0EF25
:1008C00005F030C038F02FC037F02EC036F02DC004
:1008D00035F089DE03C03CF002C03BF001C03AF0C5
:1008E00000C039F0406A3F6A3E6A8F0E3D6E95DE69
:1008F00000C035F001C036F002C037F003C038F058
:1009000003C040F002C03FF001C03EF000C03DF027
:10091000446A240E436E740E426E920E416E2ADFBC
:1009200000C035F001C036F002C037F003C038F027
:1009300003C03CF002C03BF001C03AF000C039F007
:10094000800E406E960E3F6E180E3E6E950E3D6EFA
:1009500064DE03C034F002C033F001C032F000C0E6
:1009600031F035D130C038F02FC037F02EC036F01E
:100970002DC035F038DE03C03CF002C03BF001C0B2
:100980003AF000C039F0406A3F6A3E6A8F0E3D6E11
:1009900044DE00C035F001C036F002C037F003C0BD
:1009A00038F003C040F002C03FF001C03EF000C08C
:1009B0003DF0446A240E436E740E426E920E416EF8
:1009C000D9DE00C035F001C036F002C037F003C0F8
:1009D00038F003C03CF002C03BF001C03AF000C068
:1009E00039F0800E406E960E3F6E180E3E6E950EDC
:1009F0003D6E13DE00C035F001C036F002C037F0A6
:100A000003C038F003C040F002C03FF001C03EF028
:100A100000C03DF0446A436A426A800E416EAADE1D
:100A200003C034F002C033F001C032F000C031F036
:100A3000CED030C038F02FC037F02EC036F02DC0E9
:100A400035F0D1DD03C03CF002C03BF001C03AF00C
:100A500000C039F0406A3F6A3E6A8F0E3D6EDDDDB0
:100A600000C035F001C036F002C037F003C038F0E6
:100A700003C040F002C03FF001C03EF000C03DF0B6
:100A8000446A240E436E740E426E920E416E72DE04
:100A900000C035F001C036F002C037F003C038F0B6
:100AA00003C03CF002C03BF001C03AF000C039F096
:100AB000800E406E960E3F6E180E3E6E950E3D6E89
:100AC000ACDD00C035F001C036F002C037F003C025
:100AD00038F003C040F002C03FF001C03EF000C05B
:100AE0003DF0446A436A426A810E416E43DE03C0B0
:100AF00034F002C033F001C032F000C031F067D0F2
:100B000030C038F02FC037F02EC036F02DC035F091
:100B10006ADD03C03CF002C03BF001C03AF000C007
:100B200039F0406A3F6A3E6A8F0E3D6E76DD00C046
:100B300035F001C036F002C037F003C038F003C012
:100B400040F002C03FF001C03EF000C03DF0446AFA
:100B5000240E436E740E426E920E416E0BDE00C088
:100B600035F001C036F002C037F003C038F003C0E2
:100B70003CF002C03BF001C03AF000C039F0800EFA
:100B8000406E960E3F6E180E3E6E950E3D6E45DD24
:100B900000C035F001C036F002C037F003C038F0B5
:100BA00003C040F002C03FF001C03EF000C03DF085
:100BB000446A436A426A820E416EDCDD03C034F04F
:100BC00002C033F001C032F000C031F000D031C0BB
:100BD00000F032C001F033C002F034C003F0000C6A
:100BE000E824F76AF736FB0FF66E0B0EF7220A00C1
:100BF000F550FA6E0800F550F96EC2086409320A21
:100C0000000B3D50B6083D6E036A3EC041F03E8E7B
:100C1000D8903E323F32403203320232013200324B
:100C20003D2EF6D741AE0BD0001E011E021E031E44
:100C3000002AD8B4012AD8B4022AD8B4032A85EFEE
:100C400006F0006A016A026A036A456A466A476AF0
:100C5000486A44504310421041102CE0200E496E67
:100C6000D8903D363E363F364036453646364736D6
:100C700048364450485C08E14350475C05E1425027
:100C8000465C02E14150455C0FE34150455E4250F5
:100C9000D8A0423C465E4350D8A0433C475E4450F7
:100CA000D8A0443C485ED880003601360236033670
:100CB000492ED6D7EA6A450EE96E000CE950356E2A
:100CC0003450376E19E033C040F032C03FF031C0CD
:100CD0003EF030C03DF0446A436A200E426E820E00
:100CE000416E48DD03C033F002C032F001C031F084
:100CF00000C030F0372EE7D733C040F032C03FF0AD
:100D000031C03EF030C03DF07CD703C033F002C0AC
:100D100032F001C031F000C030F033AE0DD03506F6
:100D2000358A301E311E321E331E302AD8B4312A85
:100D3000D8B4322AD8B4332A3B0E3C6E9A0E3B6E9E
:100D4000CA0E3A6E396A0A0E376E3450D8B4352A54
:100D500033C040F032C03FF031C03EF030C03DF013
:100D60003CC044F03BC043F03AC042F039C041F0CF
:100D700068DF0150EFCF30F0ECCF31F0ECCF32F044
:100D8000ECCF33F000520FE13428375C0CE03550E3
:100D90000CE00F0B375C01E03BE235BE39D035BCCF
:100DA00004D0200E30D0200E351635AA0DD0359A3D
:100DB0003450D8A435060050356E2D0E3D6E09EC2A
:100DC00002F03550006E356A3450375C0BE100504C
:100DD000356E2E0E3D6E09EC02F03550006E200E81
:100DE0003516000E300E35AA0ED0359A3450D8A4E0
:100DF00035060050356E2D0E3D6E09EC02F0355073
:100E0000006E356A300E002600C03DF009EC02F09D
:100E10003CC040F03BC03FF03AC03EF039C03DF02E
:100E2000446A436A426A0A0E416E0BDF03C03CF01B
:100E300002C03BF001C03AF000C039F0372E88D72D
:100E4000000CF86AD09EEA6AE96A939E8A8E9382C1
:100E5000939093948A94046A010E056E066A076A59
:100E6000086E09800992099409860988099A098CF3
:100E7000099E0A900A92050E0B6E0C6E0A940D6A7A
:100E80000E6A010E0F6E0A960A98136A126A116AA8
:100E9000106A0A9A030E146E186A176A166A156A9F
:100EA0001C6A1B6A1A6A196A1D6A0A9C0A8E1E6AE3
:100EB000206A1F6AC150C00B0F09C16E070EB46EC5
:100EC000C150C00B0F09C16EC090C092C094C09EAB
:100ED000C2809698C69A949E93809392010EC66E95
:100EE000000EC76ED190800ED56ECD6A000ECA6E10
:100EF000000ECB6E9484BD6AB76AB66A070EB46EF4
:100F00009250926E100E006E002EFED70000B4506C
:100F1000A19CB56A27EC00F095988C98959A8C9ACC
:100F2000959C8C9C320E356E34EC00F0640E356E60
:100F300034EC00F027EC00F0640E356E34EC00F079
:100F4000010E0C6E040E0E6E0D6A070E0F6E0A8AED
:100F5000136A126A116A106A186A176A166A156AA1
:100F60001C6A1B6A1A6A196A8CEF00F0376AE2EC95
:100F700001F003C027F002C026F001C025F000C038
:100F800024F0010E376EE2EC01F003C02BF002C03A
:100F90002AF001C029F000C028F0020E376EE2EC02
:100FA00001F003C02FF002C02EF001C02DF000C0F0
:100FB0002CF0030E376EE2EC01F003C033F002C0F8
:100FC00032F001C031F000C030F02D0E3D6E09EC62
:100FD00002F0200E3D6E09EC02F027C034F0370E0F
:100FE000356E29EC02F026C034F0370E356E29EC50
:100FF00002F025C034F0370E356E29EC02F024C023
:1010000034F0370E356E29EC02F0200E3D6E09ECFF
:1010100002F02BC034F0370E356E29EC02F02AC0F6
:1010200034F0370E356E29EC02F029C034F0370E5B
:10103000356E29EC02F028C034F0370E356E29ECFD
:1010400002F0200E3D6E09EC02F02FC034F0370E96
:10105000356E29EC02F02EC034F0370E356E29ECD7
:1010600002F02DC034F0370E356E29EC02F02CC0A2
:1010700034F0370E356E29EC02F0200E3D6E09EC8F
:1010800002F033C034F0370E356E29EC02F032C076
:1010900034F0370E356E29EC02F031C034F0370EE3
:1010A000356E29EC02F030C034F0370E356E29EC85
:1010B00002F0200E3D6E09EC02F093968A96236AA8
:1010C000B40E236E406A3F6A3E6A23C03DF0080EAC
:1010D000416E02EC00F0406A3F6A3E6A3D6A100EC3
:1010E000416E02EC00F0015001C022F000C021F07E
:1010F00093968A862238026E036A0F0E02160250F9
:10110000010B246E256A036A2230026E023202321B
:101110001F0E02160250010B266E276A036A223048
:10112000026E02323F0E02160250010B286E296A2F
:10113000D890036A2230026E010B2A6E2B6A22308D
:10114000036E2130026E0332023203320232033266
:1011500002320332023203320232030E031602500D
:10116000070B2C6E2D6A2230036E2130026E033283
:101170000232033202321F0E03160250070B2E6E8C
:101180002F6A2150070B306E316A5B0E3D6E09EC01
:1011900002F0100EE96E25C033F024C032F048ECA6
:1011A00002F0200E3D6E09EC02F0100EE96E27C031
:1011B00033F026C032F048EC02F0200E3D6E09EC10
:1011C00002F0100EE96E29C033F028C032F048EC6E
:1011D00002F0200E3D6E09EC02F0100EE96E2BC0FD
:1011E00033F02AC032F048EC02F0200E3D6E09ECDC
:1011F00002F0100EE96E2DC033F02CC032F048EC36
:1012000002F0200E3D6E09EC02F0100EE96E2FC0C8
:1012100033F02EC032F048EC02F0200E3D6E09ECA7
:1012200002F0100EE96E31C033F030C032F048ECFD
:1012300002F05D0E3D6E09EC02F0200E3D6E09ECF1
:1012400002F0A1EC02F001C024F001C034F0370E2E
:10125000356E29EC02F00D0E3D6E09EC02F00A0E1F
:101260003D6E09EC02F0BAEF02F0320E356E34EC4E
:1012700000F0C8EF02F0C80E356E34EC00F0959C1B
:101280008C8C95988C8895988C98180E006E002EF2
:10129000FED700D0959A8C8A959A8C9A00D000D06F
:1012A0000000959A8C8A959A8C9A100E006E002EEA
:1012B000FED70000959A8C8A959A8C9A00D000D01F
:1012C0000000010E2C6E33EC04F000C024F001C0CD
:1012D00025F002C026F003C027F0020E2C6E33EC7E
:1012E00004F000C028F001C029F002C02AF003C0B9
:1012F0002BF0030E2C6E33EC04F000C02CF001C078
:101300002DF002C02EF003C02FF0200E3D6E09EC30
:1013100002F0890EE96E27C033F026C032F025C0F6
:1013200031F024C030F0070E346EC8DC200E3D6E64
:1013300009EC02F0890EE96E2BC033F02AC032F0BE
:1013400029C031F028C030F0070E346EB7DC200E13
:101350003D6E09EC02F0890EE96E2FC033F02EC00D
:1013600032F02DC031F02CC030F0070E346EA6DC08
:10137000200E3D6E09EC02F093968A96236AB40E15
:10138000236E406A3F6A3E6A23C03DF0080E416EFC
:1013900002EC00F0406A3F6A3E6A3D6A100E416E00
:1013A00002EC00F0015001C022F000C021F0939641
:1013B0008A862238026E036A0F0E02160250010B53
:1013C000246E256A036A2230026E023202321F0E38
:1013D00002160250010B266E276A036A2230026E43
:1013E00002323F0E02160250010B286E296AD89075
:1013F000036A2230026E010B2A6E2B6A2230036EC2
:101400002130026E033202320332023203320232E0
:101410000332023203320232030E03160250070B6C
:101420002C6E2D6A2230036E2130026E033202329E
:10143000033202321F0E03160250070B2E6E2F6A64
:10144000D6EC02F002C003F00150070B306E316A97
:101450005B0E3D6E09EC02F0100EE96E25C033F014
:1014600024C032F048EC02F0200E3D6E09EC02F090
:10147000100EE96E27C033F026C032F048EC02F0BF
:10148000200E3D6E09EC02F0100EE96E29C033F01B
:1014900028C032F048EC02F0200E3D6E09EC02F05C
:1014A000100EE96E2BC033F02AC032F048EC02F087
:1014B000200E3D6E09EC02F0100EE96E2DC033F0E7
:1014C0002CC032F048EC02F0200E3D6E09EC02F028
:1014D000100EE96E2FC033F02EC032F048EC02F04F
:1014E000200E3D6E09EC02F0100EE96E31C033F0B3
:1014F00030C032F048EC02F05D0E3D6E09EC02F0B7
:10150000200E3D6E09EC02F0A1EC02F001C024F0C7
:1015100001C034F0370E356E29EC02F00D0E3D6E31
:1015200009EC02F00A0E3D6E09EC02F0FFD4030054
:020000040030CA
:0E00000027CC390E0087A1000FC00FE00F4083
:00000001FF
;PIC18F4550
;CRC=030F CREATED="25-IV-11 23:11"
/Modules/TDC/GP201A/SW/PICinterface/main.pjt
0,0 → 1,32
[PROJECT]
Target=.\main.hex
Development_Mode=
Processor_Text=PIC18F4550
ToolSuite=CCS
Processor=0x4550
[.\main]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=.\main.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=main.c
2=main.h
3=C:\Program Files\PICC\devices\18F4550.h
4=GP2.h
5=GP2.c
6=ds1820.c
7=1wire.c
8=
[Target Data]
OptionString=-p +FH
FileList=D:\MLAB\Modules\TDC\GP201A\SW\PICinterface\main.c
[Units]
Count=1
1=main (main)
/Modules/TDC/GP201A/SW/PICinterface/main.h
0,0 → 1,41
#include <18F4550.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1 //System Clock by 1
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled
 
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8)
 
#define TDC_ENABLE PIN_B3 //enable pin for SPI communication with TDC
#use spi(DI=PIN_B1, DO=PIN_B0, CLK=PIN_B2, stream=TDC_stream, bits=32,baud=9600) // uses software SPI
 
 
 
/Modules/TDC/GP201A/SW/PICinterface/1wire.c
0,0 → 1,43
 
void onewire_reset()
{
output_low(ONE_WIRE_PIN);
delay_us(500);
output_float(ONE_WIRE_PIN);
delay_us(500);
output_float(ONE_WIRE_PIN);
}
 
 
void onewire_write(int data)
{
int count;
 
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 );
output_bit(ONE_WIRE_PIN, shift_right(&data,1,1));
 
delay_us( 60 );
output_float(ONE_WIRE_PIN);
delay_us( 2 );
}
}
 
 
int onewire_read()
{
int count, data;
 
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 );
output_float(ONE_WIRE_PIN);
delay_us( 8 );
shift_right(&data,1,input(ONE_WIRE_PIN));
delay_us( 120 );
}
return( data );
}
/Modules/TDC/GP201A/SW/PICinterface/ds1820.c
0,0 → 1,25
#include "1wire.c"
 
float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;
 
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
 
while (busy == 0) busy = onewire_read();
 
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
temp3 = make16(temp2, temp1);
 
result = (float) temp3 / 16.0; //calculation pro DS18B20 with 0.1 deg C
 
return(result);
}