Problem with comparison.
/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); |
} |
/Modules/TDC/GP201A/SW/PICinterface/main.c |
---|
0,0 → 1,87 |
#include "main.h" |
#define VERSION 0.1 |
#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() |
{ |
float temperature; |
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(); |
hit1=TDC_MRANGE2_HIT1_START; |
hit2=TDC_MRANGE2_HIT2_2CH1; |
hitin1=TDC_HITIN1_2; |
hitin2=TDC_HITIN1_0; |
en_int= 0xFF; //TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; |
en_err_val=TDC_ERRVAL_EN; |
delval1=0x0; |
delval2=0x0; |
delval3=0x0; |
TDC_update_registers(); |
output_low(START); |
output_low(STOP1); |
output_low(STOP2); |
TDC_start_cal(); |
delay_ms(50); |
while(true) |
{ |
temperature = ds1820_read(); |
TDC_init(); |
delay_ms(50); |
printf("Temp: %f \r\n", temperature); |
delay_ms(50); |
printf("status: %LX \r\n", TDC_get_status()); |
delay_us(10); |
TDC_start_cycle(); |
delay_us(10); |
output_high(START); |
delay_us(1); |
output_low(START); |
delay_us(500); |
output_high(STOP1); |
delay_us(10); |
output_low(STOP1); |
delay_us(500); |
output_high(STOP1); |
delay_us(10); |
output_low(STOP1); |
delay_us(500); |
output_high(STOP1); |
delay_us(10); |
output_low(STOP1); |
delay_ms(100); |
printf("status: %LX \r\n", TDC_get_status()); |
delay_ms(50); |
printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
delay_ms(500); |
}; |
} |
/Modules/TDC/GP201A/SW/PICinterface/main.hex |
---|
0,0 → 1,259 |
:020000040000FA |
:10000000DEEF05F0F76A140FF66E000EF722090016 |
:10001000F550120054656D703A202566200D0A00D7 |
:10002000F76A300FF66E000EF7220900F550120045 |
:100030007374617475733A20254C58200D0A0000C2 |
:10004000F76A500FF66E000EF7220900F550120005 |
:100050006D656173757265643A20254C582C2025B6 |
:100060004C582C20254C582C20254C58200D0A008B |
:100070003C50200807E03D6E383639363A363B367C |
:100080003D2EFAD79382939093948A943CC03DF08E |
:100090008A843BAE8A903BBE8A80383639363A36FF |
:1000A0003B368A94003601360236033681A2009030 |
:1000B00081B200803D2EECD7000C93968A963B6A65 |
:1000C0003A6A396A500E386E080E3C6ED1DF93964C |
:1000D0008A8647EF06F093968A963B6A3A6A396AAF |
:1000E000800E386E080E3C6EC3DF3B6A3A6A396A8E |
:1000F00005C038F0040E3C6EBBDF3B6A3A6A396AD1 |
:1001000006C038F0040E3C6EB3DF3B6A3A6A396AC7 |
:1001100007C038F0020E3C6EABDF3B6A3A6A396AC0 |
:1001200008C038F0020E3C6EA3DF3B6A3A6A396AB7 |
:1001300009C038F0020E3C6E9BDF000E0AB0010EC3 |
:100140003B6A3A6A396A386E010E3C6E91DF000EE6 |
:100150000AB2010E3B6A3A6A396A386E010E3C6E89 |
:1001600087DF000E0AB4010E3B6A3A6A396A386EBC |
:10017000010E3C6E7DDF000E0AB6010E3B6A3A6A44 |
:10018000396A386E010E3C6E73DF000E0AB8010E3C |
:100190003B6A3A6A396A386E010E3C6E69DF000EBE |
:1001A0000ABA010E3B6A3A6A396A386E010E3C6E31 |
:1001B0005FDF000E0ABC010E3B6A3A6A396A386E8C |
:1001C000010E3C6E55DF000E0ABE010E3B6A3A6A14 |
:1001D000396A386E010E3C6E4BDF000E0BB0010E1B |
:1001E0003B6A3A6A396A386E010E3C6E41DF000E96 |
:1001F0000BB2010E3B6A3A6A396A386E010E3C6EE8 |
:1002000037DF93968A8693968A963B6A3A6A396A6A |
:10021000810E386E080E3C6E2BDF3B6A3A6A396AF3 |
:100220000CC038F0040E3C6E23DF3B6A3A6A396A30 |
:100230000DC038F0040E3C6E1BDF000E0BB4010E37 |
:100240003B6A3A6A396A386E010E3C6E11DF3B6ACE |
:100250003A6A396A010E386E3C6E0ADF3B6A3A6AC6 |
:10026000396A0EC038F0030E3C6E02DF3B6A3A6A10 |
:10027000396A0FC038F0030E3C6EFADE3B6A3A6A08 |
:10028000396A386A080E3C6EF3DE93968A86939636 |
:100290008A963B6A3A6A396A820E386E200E3C6E44 |
:1002A000E7DE3B6A3A6A396A10C038F0030E3C6EEA |
:1002B000DFDE000E0BB6010E3B6A3A6A396A386E11 |
:1002C000010E3C6ED5DE000E0BB8010E3B6A3A6A99 |
:1002D000396A386E010E3C6ECBDE14C03BF013C0A1 |
:1002E0003AF012C039F011C038F0130E3C6EC0DE87 |
:1002F00093968A8693968A963B6A3A6A396A830EFF |
:10030000386E200E3C6EB4DE3B6A3A6A396A386A4F |
:10031000020E3C6EADDE000E0BBA010E3B6A3A6A6D |
:10032000396A386E010E3C6EA3DE3B6A3A6A396A5E |
:1003300015C038F0020E3C6E9BDE19C03BF018C0B1 |
:100340003AF017C039F016C038F0130E3C6E90DE4C |
:1003500093968A8693968A963B6A3A6A396A840E9D |
:10036000386E200E3C6E84DE3B6A3A6A396A040EAF |
:10037000386E050E3C6E7CDE1DC03BF01CC03AF0B2 |
:100380001BC039F01AC038F0130E3C6E71DE939624 |
:100390008A8693968A963B6A3A6A396A850E386EDF |
:1003A000200E3C6E65DE3B6A3A6A396A1EC038F040 |
:1003B000030E3C6E5DDE000E0BBC010E3B6A3A6A1A |
:1003C000396A386E010E3C6E53DE000E0BBE010E14 |
:1003D0003B6A3A6A396A386E010E3C6E49DE3B6A06 |
:1003E0003A6A396A1FC038F0030E3C6E41DE3B6A40 |
:1003F0003A6A21C039F020C038F0100E3C6E38DE69 |
:1004000093968A865FEF06F093968A963B6A3A6ADD |
:10041000396A040E386E080E3C6E2ADE93968A8680 |
:1004200067EF06F0EA6A270EE96EEF500DE0060E60 |
:10043000016E006A002EFED7012EFBD77B0E006EE8 |
:10044000002EFED7EF2EF3D7000C030E305E09E32B |
:10045000EA6A300EE96EEF5004E001D000D0EF2ED2 |
:10046000FDD7000C96948D94020E2F6EF90E306E0F |
:10047000ECDF2F2EFBD79684020E2F6EF90E306E16 |
:10048000E4DF2F2EFBD79684000C306A305007082B |
:1004900019E396948D94030E006E002EFED7D8803B |
:1004A0002F3202E28D9401D08D849694630E006EFB |
:1004B000002EFED700D09684030E006E002EFED7CD |
:1004C000302AE4D7000C2F6A2F50070819E39694BE |
:1004D0008D94030E006E002EFED796840D0E006ED6 |
:1004E000002EFED7968484B402D0D89001D0D88054 |
:1004F0003032C70E006E002EFED700D02F2AE4D770 |
:1005000030C001F0000C8E0E006E30C001F02FC024 |
:1005100002F0036A30AE05D0011E021E022A01E17C |
:10052000012A015209E102C001F0026A080E005ED0 |
:10053000015202E1006A0AD0D89001BE04D002360E |
:1005400001360006F9D730BE01D0019E7AEF03F0E4 |
:100550003350D8B4A5D03F6E3750D8B4A1D03F5E49 |
:1005600005E37F0E3F26D8B09BD006D0810E3F5EBC |
:10057000D8A096D0D8B494D03FC000F0016A026AE7 |
:10058000036A3E6A34C03DF03D8E35C03CF036C053 |
:100590003BF0190E3F6E3A503B5E0DE2010E3C5EA1 |
:1005A0000AE23D5E08E23E5E06E23E2A3D2A3C2A21 |
:1005B0003A503B2628D039503C5E12E2010E3D5E97 |
:1005C0000FE23E5E0DE23E2A3D2A39503C263A506B |
:1005D0003B2619E33C2A17E13D2A15E13E2A13D0B8 |
:1005E000385080093D5E0EE2010E3E5E0BE23E2A6F |
:1005F000385080093D2639503C26E9E33D2AE7E1A1 |
:100600003E2AE5D703803F2E01D00BD0D8903B3651 |
:100610003C363D363E36D8900336023601364036FB |
:10062000BAD740A006D0D89001320232033240320D |
:1006300002D0000635E040BE1ED0D8903B363C3696 |
:100640003D363E363A503B5E07E2010E3C5E04E228 |
:100650003D5E02E23E5E1AE339503C5E05E2010E69 |
:100660003D5E02E23E5E12E3385080093D5E03E2E9 |
:10067000010E3E5E0BE3032A09E1022A07E1012A8B |
:1006800005E1002A0DE001320232033234C03FF0AE |
:1006900038503F1A3FAE02D0018E06D0019E04D0E2 |
:1006A000006A016A026A036A90EF03F0266ADADEE2 |
:1006B000CC0E2F6EEADE440E2F6EE7DE265204E1EA |
:1006C00002DF01C026F0FAD7CDDECC0E2F6EDDDEC4 |
:1006D000BE0E2F6EDADEF7DE01C027F0F4DE01C0B9 |
:1006E00028F028C02AF027C029F02AC030F029C0FD |
:1006F0002FF009D700C02FF001C030F002C031F058 |
:1007000003C032F003C036F002C035F001C034F04F |
:1007100000C033F03A6A396A386A830E376E18D7E8 |
:1007200003C02EF002C02DF001C02CF000C02BF051 |
:100730002BC000F02CC001F02DC002F02EC003F041 |
:100740006CEF06F093968A963B6A3A6A396A700EA5 |
:10075000386E080E3C6E8CDC93968A8675EF06F038 |
:10076000939E8A9E080E016E00D00000018E0ED06E |
:10077000019E3832D8B08A8ED8A08A9E018C06D0CD |
:10078000019C012EF6D700D000008A8EA70EE96EDC |
:10079000E92EFED700D001BEEBD701BCF1D7000C8B |
:1007A0003350D8B471D0006E3750D8B46DD0002615 |
:1007B00004E3810E002668E204D07F0E005E64E34D |
:1007C00063E034C03BF038503B1A348E388E3650DC |
:1007D0003A02F4CF3DF035503902F4CF03F0F3CFB5 |
:1007E0003CF03A02F3503D26F4503C22000E032226 |
:1007F00036503902F3503D26F4503C22000E026A76 |
:100800000322022234503A02F3503C26F4500322D1 |
:10081000000E022234503902F3500326F450022213 |
:10082000000E016A012236503802F3503C26F45083 |
:100830000322000E0222012235503802F350032613 |
:10084000F4500222000E012234503802F3500226E6 |
:10085000F4500122002A01BE05D03C360336023690 |
:1008600001360006000E3CAE0AD0032A0222012205 |
:10087000015005E1025003E1035001E1002A3BBEB3 |
:10088000018E3BAE019E04D0006A016A026A036ACF |
:10089000BBEF04F03350B608336E036A34C037F050 |
:1008A000348ED8903432353236320332023201324D |
:1008B0000032332EF6D737AE0BD0001E011E021EBB |
:1008C000031E002AD8B4012AD8B4022AD8B4032AB5 |
:1008D000CEEF04F0006A016A026A036A3B6A3C6A6E |
:1008E0003D6A3E6A3A503910381037102CE0200E1D |
:1008F0003F6ED89033363436353636363B363C3656 |
:100900003D363E363A503E5C08E139503D5C05E1EB |
:1009100038503C5C02E137503B5C0FE337503B5EA4 |
:100920003850D8A0383C3C5E3950D8A0393C3D5EA8 |
:100930003A50D8A03A3C3E5ED880003601360236A6 |
:1009400003363F2ED6D7EA6A3B0EE96E000CE9501B |
:100950002B6E2A502D6E19E029C036F028C035F0D4 |
:1009600027C034F026C033F03A6A396A200E386E58 |
:10097000820E376E15D703C029F002C028F001C0DF |
:1009800027F000C026F02D2EE7D729C036F028C06A |
:1009900035F027C034F026C033F07CD703C029F0EF |
:1009A00002C028F001C027F000C026F029AE0DD00B |
:1009B0002B062B8A261E271E281E291E262AD8B45F |
:1009C000272AD8B4282AD8B4292A3B0E326E9A0E88 |
:1009D000316ECA0E306E2F6A0A0E2D6E2A50D8B4B0 |
:1009E0002B2A29C036F028C035F027C034F026C0A5 |
:1009F00033F032C03AF031C039F030C038F02FC097 |
:100A000037F068DF0150EFCF26F0ECCF27F0ECCFC6 |
:100A100028F0ECCF29F000520FE12A282D5C0CE0E1 |
:100A20002B500CE00F0B2D5C01E037E22BBE35D0D4 |
:100A30002BBC04D0200E2DD0200E2B162BAA0CD0B0 |
:100A40002B9A2A50D8A42B0600502B6E2D0E386EF0 |
:100A500087DE2B50006E2B6A2A502D5C0AE1005075 |
:100A60002B6E2E0E386E7CDE2B50006E200E2B1659 |
:100A7000000E300E2BAA0DD02B9A2A50D8A42B068C |
:100A800000502B6E2D0E386E6BDE2B50006E2B6AD5 |
:100A9000300E002600C038F063DE32C036F031C0C0 |
:100AA00035F030C034F02FC033F03A6A396A386A12 |
:100AB0000A0E376E0FDF03C032F002C031F001C002 |
:100AC00030F000C02FF02D2E8CD791EF06F09396CA |
:100AD0008A963B6A3A6A396AB40E386E080E3C6EE2 |
:100AE00038EC00F03B6A3A6A396A386A100E3C6E9C |
:100AF00038EC00F0015001C027F000C026F09396BA |
:100B00008A8626C001F027C002F0000C37BE0FD045 |
:100B10000F0E006E363800160A0E005C03E2300E2F |
:100B2000002602D03750002600C038F019DE0F0E24 |
:100B300036160A0E365C02E2300E02D0379E37506F |
:100B4000362636C038F00CDE000C93968A963B6A47 |
:100B50003A6A396A010E386E080E3C6E38EC00F0C5 |
:100B600093968A86C7EF06F093968A96B00E322443 |
:100B7000FF0F376E3B6A3A6A396A386E200E3C6E58 |
:100B800038EC00F03B6A3A6A396A386A200E3C6EEB |
:100B900038EC00F0015003C036F002C035F001C05F |
:100BA00034F000C033F093968A8633C000F034C02E |
:100BB00001F035C002F036C003F0000CF86AD09E98 |
:100BC000EA6AE96A939E8A8E9382939093948A94B8 |
:100BD000C150C00B0F09C16E070EB46E056A066ADC |
:100BE000076A086A010E096E0A800A920A940A8648 |
:100BF0000A880A9A0A8C0A9E0B900B92050E0C6EBC |
:100C00000D6E0B940E6A0F6A010E106E0B960B9808 |
:100C1000116A126A136A146A0B9A030E156E166A29 |
:100C2000176A186A196A1A6A1B6A1C6A1D6A1E6AA0 |
:100C30000B9C0B8E1F6AC150C00B0F09C16EC09078 |
:100C4000C092C094C09EC280B098C69A949E938071 |
:100C50009392010EC66E000EC76ED190800ED56EB7 |
:100C6000CD6A000ECA6E000ECB6E9484BD6AB76A60 |
:100C7000B66A070EB46E9250926E100E006E002E81 |
:100C8000FED70000B450A19CB56A5DEF00F0010EE4 |
:100C90000D6E030E0C6E020E0F6E0E6AFF0E106EBE |
:100CA0000B8A146A136A126A116A196A186A176A37 |
:100CB000166A1D6A1C6A1B6A1A6A6BEF00F0959827 |
:100CC0008C98959A8C9A959C8C9C04EF02F0320E2D |
:100CD000276E12EC02F0EAD403C025F002C024F023 |
:100CE00001C023F000C022F02DD5320E276E12EC89 |
:100CF00002F0266A265002EC00F0262A006E386EBA |
:100D00002FDD060E265CF6E1890EE96E25C029F07E |
:100D100024C028F023C027F022C026F0020E2A6E3D |
:100D200016D6200E386E1CDD0D0E386E19DD0A0E3B |
:100D3000386E16DD320E276E12EC02F0C8DE02C0ED |
:100D400027F001C026F0286A285010EC00F0282A6D |
:100D5000006E386E05DD080E285CF6E127C036F01F |
:100D6000370E376ED3DE26C036F0370E376ECEDE46 |
:100D7000200E386EF5DC0D0E386EF2DC0A0E386E81 |
:100D8000EFDC100E006E002EFED70000DED6100E37 |
:100D9000006E002EFED7000095988C8800D000D001 |
:100DA000000095988C98020E266EF90E306E25EC98 |
:100DB00002F0262EFAD7959A8C8A100E006E002E1D |
:100DC000FED70000959A8C9A020E266EF90E306EB0 |
:100DD00025EC02F0262EFAD7959A8C8A100E006E1A |
:100DE000002EFED70000959A8C9A020E266EF90E00 |
:100DF000306E25EC02F0262EFAD7959A8C8A100ECA |
:100E0000006E002EFED70000959A8C9A640E276E15 |
:100E100012EC02F05CDE02C027F001C026F0286A66 |
:100E2000285010EC00F0282A006E386E99DC080E6D |
:100E3000285CF6E127C036F0370E376E67DE26C035 |
:100E400036F0370E376E62DE200E386E89DC0D0EFE |
:100E5000386E86DC0A0E386E83DC320E276E12EC9A |
:100E600002F0010E326E80DE03C029F002C028F0CD |
:100E700001C027F000C026F0020E326E75DE03C0FE |
:100E80002DF002C02CF001C02BF000C02AF0030EA0 |
:100E9000326E6ADE03C031F002C030F001C02FF0C4 |
:100EA00000C02EF0040E326E5FDE03C035F002C0CB |
:100EB00034F001C033F000C032F0366A365020EC16 |
:100EC00000F0362A006E386E4BDC0A0E365CF6E116 |
:100ED00029C036F0370E376E19DE28C036F0370ECF |
:100EE000376E14DE27C036F0370E376E0FDE26C0A1 |
:100EF00036F0370E376E0ADE2C0E386E31DC200EDF |
:100F0000386E2EDC2DC036F0370E376EFFDD2CC06C |
:100F100036F0370E376EFADD2BC036F0370E376EEF |
:100F2000F5DD2AC036F0370E376EF0DD2C0E386E48 |
:100F300017DC200E386E14DC31C036F0370E376EF9 |
:100F4000E5DD30C036F0370E376EE0DD2FC036F00D |
:100F5000370E376EDBDD2EC036F0370E376ED6DD3E |
:100F60002C0E386EB0EC03F0200E386EB0EC03F0AF |
:100F700035C036F0370E376EC9DD34C036F0370E67 |
:100F8000376EC4DD33C036F0370E376EBFDD32C08A |
:100F900036F0370E376EBADD200E386EB0EC03F047 |
:100FA0000D0E386EB0EC03F00A0E386EB0EC03F0A4 |
:100FB000020E266EFA0E276E12EC02F0262EFAD7DB |
:040FC0008AD60300CA |
:020000040030CA |
:0E00000027CC390E0087A1000FC00FE00F4083 |
:00000001FF |
;PIC18F4550 |
;CRC=2145 CREATED="08-I-11 13:01" |
/Modules/TDC/GP201A/SW/PICinterface/main.pjt |
---|
0,0 → 1,30 |
[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=ds1820.c |
3=1wire.c |
4= |
5=GP2.h |
6= |
[Target Data] |
OptionString=-p +FH |
FileList=D:\MLAB\Modules\TDC\GP201A\SW\PICinterface\.\main.c |
[Units] |
Count=1 |
1=.\main.c (main) |
/Modules/TDC/GP201A/SW/PICinterface/GP2.c |
---|
0,0 → 1,198 |
//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; |
//}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 - 1); |
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_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); |
// update reg1 |
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); |
// 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); |
} |
/Modules/TDC/GP201A/SW/PICinterface/GP2.h |
---|
0,0 → 1,152 |
//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_7 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 0 |
#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.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) // uses software SPI |