ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
GP22_ATY.c
Go to the documentation of this file.
1
30#ifndef __GP22_ATY_C
31#define __GP22_ATY_C
32
33#include "GP22_ATY.h"
34
35/******************************* For user *************************************/
36
37/******************************************************************************/
38
39/* Basic **********************************************************************/
45{
47 SPI_Write(&data_t, 1);
49}
50
51void GP22_WriteReg(uint8_t opcode_address, uint32_t reg_data)
52{
53 uint8_t temp_uint8[4];
54 temp_uint8[0] = reg_data >> 24;
55 temp_uint8[1] = reg_data >> 16;
56 temp_uint8[2] = reg_data >> 8;
57 temp_uint8[3] = reg_data;
59 SPI_Write(&opcode_address, 1);
60 SPI_Write(temp_uint8, 4);
62}
63
65{
66 uint8_t data_t[4] = {0};
67
69 SPI_Write(&opcode_address, 1);
70 SPI_Read(data_t, 4);
72
73#ifdef __DEBUG_GP22_OPCODE_ATY
74 printf("\r\nRead opcode %02X: 0x%02X%02X%02X%02X",
75 opcode_address, data_t[0], data_t[1], data_t[2], data_t[3]);
76#endif /* __DEBUG_GP22_OPCODE_ATY */
77
78 return (((uint32_t)data_t[0] << 24) + ((uint32_t)data_t[1] << 16)
79 + ((uint32_t)data_t[2] << 8) + ((uint32_t)data_t[3]));
80}
81
82void GP22_Reset(void)
83{
85 DelayMs(1);
87 DelayMs(1);
89 DelayMs(1);
91}
92
93// TODO: set generic
95{
96 uint32_t errTimeCount = 0;
97
98 // GP22_ENABLE;
99 while(GP22_READ_INT_H)
100 {
101 errTimeCount++;
102 if(errTimeCount > 12000) // 24000 About 36ms at 64M HCLK, 1.25MIPS/Mhz for arm
103 {
104 errTimeCount = 0;
105#ifdef __DEBUG_GP22_ATY
106 printf("\r\nERR - INT timeout %d", step);
107#endif /* __DEBUG_GP22_ATY */
108 return step;
109 }
110 }
111 return 0;
112}
113
115{
116 uint8_t i = 0;
117 uint32_t temp_uint32 = 0;
118
119 for(i = 0; i < 5; i++)
120 {
121 GP22_Reset();
122
123 GP22_WriteReg(GP22_OPCODE_WRITE_REG | 0x01, ((uint32_t)data_t << 24) | 0x00123456);
124 DelayMs(2);
126#ifdef __DEBUG_GP22_ATY
127 printf("\r\nSPIT - 0x%08X", temp_uint32);
128#endif /* __DEBUG_GP22_ATY */
129 if((temp_uint32 >> 24) == data_t)
130 return 0;
131 }
132#ifdef __DEBUG_GP22_ATY
133 printf("\r\nERR - SPI Commucate Err!");
134#endif /* __DEBUG_GP22_ATY */
135 return 1;
136}
137
139{
140 uint8_t temp_uint8 = GP22_OPCODE_READ_ID;
141 uint8_t id[8] = {0};
143 SPI_Write(&temp_uint8, 1);
144 SPI_Read(id, 8);
146
147#ifdef __DEBUG_GP22_ATY
148 printf("\r\nRID - Read id: 0x%02X%02X%02X%02X%02X%02X%02X%02X",
149 id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
150 // printf("\r\nRID - Save id: 0x%02X%02X%02X%02X%02X%02X%02X%02X",
151 // GP22_Ids[0], GP22_Ids[1], GP22_Ids[2], GP22_Ids[3], GP22_Ids[4],
152 // GP22_Ids[5], GP22_Ids[6], GP22_Ids[7]);
153#endif /* __DEBUG_GP22_ATY */
154
155 if((id[0] == GP22_Ids[0]) && (id[1] == GP22_Ids[1]) && (id[2] == GP22_Ids[2])
156 && (id[3] == GP22_Ids[3]) && (id[4] == GP22_Ids[4]) && (id[5] == GP22_Ids[5])
157 && (id[6] == GP22_Ids[6]))
158 {
159 return 0;
160 }
161 else
162 {
163#ifdef __DEBUG_GP22_ATY
164 printf("\r\nERR - Read wrong id number!");
165#endif /* __DEBUG_GP22_ATY */
166 return 1;
167 }
168
169}
170
172{
173 uint16_t statusCode = 0;
174
176
177#ifdef __DEBUG_GP22_ATY
178 printf("\r\nSTAT - Code: 0x%04X | ALU - %d | HIT1 - %d | HIT2 - %d",
179 statusCode,
180 statusCode & 0x0007,
181 (statusCode >> 3) & 0x0007,
182 (statusCode >> 6) & 0x0007);
183 //Bit9: Timeout_TDC
184 if((statusCode & 0x0200) == 0x0200)
185 printf("\r\nERR - Indicates an overflow of the TDC unit");
186 //Bit10: Timeout_Precounter
187 if((statusCode & 0x0400) == 0x0400)
188 printf("\r\nERR - Indicates an overflow of the 14 bit precounter in MR 2");
189 //Bit11: Error_open
190 if((statusCode & 0x0800) == 0x0800)
191 printf("\r\nERR - Indicates an open sensor at temperature measurement");
192 //Bit12: Error_short
193 if((statusCode & 0x1000) == 0x1000)
194 printf("\r\nERR - Indicates a shorted sensor at temperature measurement");
195 //Bit13: EEPROM_eq_CREG
196 if((statusCode & 0x2000) != 0x2000)
197 printf("\r\nERR - The content of the configuration registers not equals the EEPROM");
198 //Bit14: EEPROM_DED
199 if((statusCode & 0x4000) == 0x4000)
200 printf("\r\nERR - Double error detection. A multiple error has been detected whcich can not be corrected");
201 //Bit15: EEPROM_Error
202 if((statusCode & 0x8000) == 0x8000)
203 printf("\r\nERR - Single error in EEPROM which has been corrected");
204#endif /* __DEBUG_GP22_ATY */
205
206 return statusCode;
207}
208
209// TODO: E2 tested is not reality, state changed with power time
211{
212 uint8_t errCount = 5;
213 uint16_t statusCode = 0x0000;
214
215 while(errCount != 0)
216 {
217 errCount--;
220 if((statusCode & 0x2000) != 0x2000)
221 {
223 DelayMs(100);
225 {
226#ifdef __DEBUG_GP22_ATY
227 printf("\r\nERR - Write E2 timeout");
228#endif /* __DEBUG_GP22_ATY */
229 return 1;
230 }
231 }
232 else
233 {
234#ifdef __DEBUG_GP22_ATY
235 printf("\r\nCE2 - Compare E2 success");
236#endif /* __DEBUG_GP22_ATY */
237 return 0;
238 }
239 }
240#ifdef __DEBUG_GP22_ATY
241 printf("\r\nERR - Compare E2 failed");
242#endif /* __DEBUG_GP22_ATY */
243 return 1;
244}
245
247{
248 uint8_t errCount = 5;
249 uint32_t hscReadValue;
250 float correctionFactor;
251
252 while(errCount != 0)
253 {
254 errCount--;
256 // EN_START need to set high
258 if(GP22_WaitInt(GP22_STEP_START_TEMP) != 0) continue;
259
260 hscReadValue = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x00);
261 // CLKHS periods * 1000 / 32.768 us
262 // 0: 2 periods = 61.03515625us
263 // 1: 4 periods = 122.0703125us
264 // 2: 8 periods = 244.140625us
265 // 3: 16 periods = 488.28125us
266 correctionFactor = ((1 << (GP22_CLKHS_PERIOD + 1)) * 1000 / 32.768)
267 / (hscReadValue / 65536) * GP22_CLKHS_FREQ;
269 correctionFactor * GP22_CLKHS_FREQ;
270#ifdef __DEBUG_GP22_ATY
271 printf("\r\nCHSC - Theoretical value: 0x%08X - %1.6f",
272 hscReadValue, (float)hscReadValue / 65536);
273 printf("\r\nCHSC - Correction factor for clock: %.6f", correctionFactor);
274 printf("\r\nCHSC - Calibrated internal clock frequency: %.6fMHz - %.6fns",
276#endif /* __DEBUG_GP22_ATY */
277 return 0;
278 }
279
280 return 1;
281}
282
284{
285 uint8_t errCount = 5;
286 uint32_t temp_uint32[4] = {0};
287 float tempRefResFactor = 0.0;
288 float tempRealRes[2] = {0.0};
289
290 while(errCount != 0)
291 {
292 errCount--;
295 if(GP22_WaitInt(GP22_STEP_START_TEMP) != 0) continue;
296 // GP22_AnalyseErrCode();
297
298 temp_uint32[0] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x00);
299 temp_uint32[1] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x01);
300 temp_uint32[2] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x02);
301 temp_uint32[3] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x03);
302 tempRefResFactor =
303 (float)(temp_uint32[2] + temp_uint32[3]) / 2
305 // tempRealRes[0] = (float)temp_uint32[0] / GP22_CALC_CLKHS_FREQ / tempRefRes;
306 // tempRealRes[0] =
307 // (GP22_TEMP_REF_RES * tempRealRes[0]) / (GP22_TEMP_REF_RES - tempRealRes[0]);
308 // tempRealRes[1] = (float)temp_uint32[1] / GP22_CALC_CLKHS_FREQ / tempRefRes;
309 // tempRealRes[1] =
310 // (GP22_TEMP_REF_RES * tempRealRes[1]) / (GP22_TEMP_REF_RES - tempRealRes[1]);
311 // tempRealValue[1] = ALGO_ResToKelvinTemp(tempRealRes[1], 10, 3937);
312 tempRealRes[0] = (float)temp_uint32[0] / GP22_CALC_CLKHS_FREQ / tempRefResFactor;
313 tempRealValue[0] = ALGO_ResToKelvinTemp(tempRealRes[0], 10, 4100);
314 tempRealRes[1] = (float)temp_uint32[1] / GP22_CALC_CLKHS_FREQ / tempRefResFactor;
315 tempRealValue[1] = ALGO_ResToKelvinTemp(tempRealRes[1], 10, 3950);
316#ifdef __DEBUG_GP22_ATY
317 printf("\r\nSTEMP - Temp reg: 0x%08X - 0x%08X - 0x%08X - 0x%08X",
318 temp_uint32[0], temp_uint32[1], temp_uint32[2], temp_uint32[3]);
319 printf("\r\nSTEMP - Temp reg: %d - %d - %d - %d",
320 temp_uint32[0], temp_uint32[1], temp_uint32[2], temp_uint32[3]);
321 printf("\r\nSTEMP - PT1 res: %f KOhm - %f C", tempRealRes[0], tempRealValue[0]);
322 printf("\r\nSTEMP - PT2 res: %f KOhm - %f C", tempRealRes[1], tempRealValue[1]);
323#endif /* __DEBUG_GP22_ATY */
324 return 0;
325 }
326
327 return 1;
328}
329
330
331
332
333
334
335
336/* Use ************************************************************************/
338uint8_t GP22_Ids[8] = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6};
340
342float tempRealValue[2] = {0.0};
343float echoTimeDetect[2] = {0};
344float echoTimeCalc[2] = {0};
345float speedWave[2] = {0};
347
349float usDistance = 0;
350
355
356
357// #define GP22_MEASURE_US_ANALOG
358// #define GP22_MEASURE_US_DIGITAL
359#define GP22_MEASURE_UsWave1MHz
360// #define GP22_MEASURE_UsWave1MHz
361
362/******************************************************************************/
363#if defined(GP22_MEASURE_UsWave1MHz)
365{
366 // 630BE800
368 | GP22_CFG0_ANZ_FIRE_0 * 1 // 3-6 pulse
369 | GP22_CFG0_DIV_FIRE_0 * 3 // 0CLK | 3FIRE 1MHz pulse
374 // | GP22_CFG0_NO_CAL_AUTO * 1
375 | GP22_CFG0_MESSB2 * 1
376
378 | GP22_CFG0_TCYCLE * 1
381 | GP22_Ids[0];
382 // 194913F1
384 | GP22_CFG1_HIT2_0 * 2
385 | GP22_CFG1_HIT1_0 * 1
391 // | GP22_CFG1_EN_FAST_INIT * 1
392 | GP22_Ids[1];
393 // A00000F2
398 // | GP22_CFG2_RFEDGE2 * 0 // 0: rising or falling, 1: and
399 | GP22_CFG2_RFEDGE1 * 0 // 0: rising or falling, 1: and
401 | GP22_Ids[2];
402 // 000000F3
411 | GP22_Ids[3];
412 // 200000F4
414 | GP22_CFG4FW_DIS_PW * 1 // 1: disable
415 | GP22_CFG4FW_OFFSRNG1 * (((uint16_t)offsetValue % 10) & 0x01)
416 | GP22_CFG4FW_OFFSRNG2 * (((uint16_t)offsetValue % 10) & 0x02)
417 | GP22_CFG4FW_EDGE_FW * (((uint16_t)offsetValue % 10) & 0x04)
419 // above 4 for first wave mode
420 | GP22_Ids[4];
421 // 100000F5
426 | GP22_Ids[5];
427 // 002000F6
431 // | GP22_CFG6_TW2_0 * 3
434
435 | GP22_CFG6_NEG_STOP_TEMP * 1 // Must set handly
436 // | GP22_CFG6_FIREO_DEF * 1
437 // | GP22_CFG6_TEMP_PORTDIR * 1
438 | GP22_Ids[6];
439
440 GP22_WriteReg(0x80, GP22_REG[0]);
441 GP22_WriteReg(0x81, GP22_REG[1]);
442 GP22_WriteReg(0x82, GP22_REG[2]);
443 GP22_WriteReg(0x83, GP22_REG[3]);
444 GP22_WriteReg(0x84, GP22_REG[4]);
445 GP22_WriteReg(0x85, GP22_REG[5]);
446 GP22_WriteReg(0x86, GP22_REG[6]);
447
448#ifdef __DEBUG_GP22_ATY
449 printf("\r\nREGI - 0: %08X\r\nREGI - 1: %08X\r\nREGI - 2: %08X\
450 \r\nREGI - 3: %08X\r\nREGI - 4: %08X\r\nREGI - 5: %08X\r\nREGI - 6: %08X",
451 GP22_REG[0], GP22_REG[1], GP22_REG[2],
452 GP22_REG[3], GP22_REG[4], GP22_REG[5], GP22_REG[6]);
453#endif /* __DEBUG_GP22_ATY */
454}
455
457{
458 float wavePeriod = 0.0;
459 float waveFreq = 0.0;
460
463
464 if(GP22_WaitInt(GP22_STEP_START_TOF) != 0) return 1;
465
466 // GP22_AnalyseErrCode();
471 if((GP22_REG[3] & GP22_CFG3FW_EN_FIRST_WAVE) != 0)
473
474 wavePeriod =
475 (float)((tofValue[2] - tofValue[1]) + (tofValue[1] - tofValue[0])) / 2
476 / GP22_CALC_CLKHS_FREQ / 65536; // ns
477 waveFreq = 1 / wavePeriod; // MHz
478 echoTimeDetect[0] = ((float)tofValue[0] / GP22_CALC_CLKHS_FREQ / 65536);
479 // - (wavePeriod * 2);
480 if(echoTimeDetect[0] <= 0)
483 speedWave[0] = usDistance * 1000.0 / echoTimeCalc[0];
484
485#ifdef __DEBUG_GP22_ATY
486 if((GP22_REG[3] & GP22_CFG3FW_EN_FIRST_WAVE) != 0)
487 printf("\r\nSTOF - PW1ST value: 0x%02X - %f",
488 PW1ST_ValueA, (float)(PW1ST_ValueA >> 24) / 128);
489 printf("\r\nSTOF - TOF reg: 0x%08X - 0x%08X - 0x%08X - 0x%08X",
490 tofValue[0], tofValue[1], tofValue[2], tofValue[3]);
491 printf("\r\nSTOF - TOF reg: %d - %d - %d - %d",
492 tofValue[0] / 65536, tofValue[1] / 65536,
493 tofValue[2] / 65536, tofValue[3] / 65536);
494 printf("\r\nSTOF - TOF reg: %f - %f - %f - %f",
495 (float)tofValue[0] / GP22_CALC_CLKHS_FREQ / 65536,
496 (float)tofValue[1] / GP22_CALC_CLKHS_FREQ / 65536,
497 (float)tofValue[2] / GP22_CALC_CLKHS_FREQ / 65536,
498 (float)tofValue[3] / GP22_CALC_CLKHS_FREQ / 65536);
499 printf("\r\nSTOF - Wave: %f us - %f MHz", wavePeriod, waveFreq);
500 printf("\r\nSTOF - Time: %f us - %f m/s", echoTimeCalc[0], speedWave[0]);
501 printf("\r\nStep %02d-A done! ----------------------------------------------",
503#endif /* __DEBUG_GP22_ATY */
504 return 0;
505}
506
508{
509 // cmdCode = 0xFF;
510 uint8_t errCode = 0;
511
512 if(cmdCode & GP22_STEP_RESET)
513 GP22_Reset();
514 if(cmdCode & GP22_STEP_SPI_TEST)
515 if(GP22_SpiTest(0x68)) return GP22_STEP_SPI_TEST;
516 if(cmdCode & GP22_STEP_REG_INIT
517 || cmdCode & GP22_STEP_READ_ID){
519 if(GP22_ReadId()) return GP22_STEP_READ_ID;
520 }
521 // if(cmdCode & GP22_STEP_COMPARE_E2)
522 // if(GP22_CompareE2()) return GP22_STEP_COMPARE_E2;
523 if(cmdCode & GP22_STEP_CALC_HSC)
524 if(GP22_CalcHSC()) return GP22_STEP_CALC_HSC;
525 if(cmdCode & GP22_STEP_START_TEMP)
526 if(GP22_StartTemp()) errCode = GP22_STEP_START_TEMP;
527 if(cmdCode & GP22_STEP_START_TOF)
529
530 return errCode;
531}
532
533
534
536{
537 uint8_t errCode = 0;
538#ifdef __DEBUG_GP22_ATY
539 printf("\r\nStart");
540#endif /* __DEBUG_GP22_ATY */
541 GP22_WAKE;
542 errCode = GP22_Process_UsWave1MHz(cmdCode);
543 // GP22_AnalyseErrCode();
544#ifdef __DEBUG_GP22_ATY
545 printf("\r\nStep %02d done! ------------------------------------------------", errCode);
546 printf("\r\nOver!");
547#endif /* __DEBUG_GP22_ATY */
548
549 return errCode;
550}
551
552
553
554
555
556#elif defined(GP22_MEASURE_US_DIGITAL)
557void GP22_RegInitUs_Digital(void)
558{
561 // | GP22_CFG0_ANZ_FIRE_0 * 14
567 | GP22_CFG0_MESSB2 * 1
568 | GP22_Ids[0];
570 | GP22_CFG1_HIT2_0 * 2
571 | GP22_CFG1_HIT1_0 * 1
577 | GP22_Ids[1];
583 | GP22_Ids[2];
586 // | GP22_CFG3FW_EN_FIRST_WAVE * 1
592 | GP22_Ids[3];
594 // | GP22_CFG4FW_DIS_PW * 1
595
596 // | GP22_CFG4FW_OFFSRNG2 * 1
597 // | GP22_CFG4FW_OFFSRNG1 * 1
598 // | GP22_CFG4FW_EDGE_FW * 1
599 // | GP22_CFG4FW_OFFS_0 * 15
600 // | GP22_CFG4FW_OFFS_0 * 16
601 | GP22_Ids[4];
603 | GP22_CFG5_CON_FIRE_0 * 1
605 | GP22_CFG5_PHFIRE_0 * 0x5555
606 | GP22_Ids[5];
608 // | GP22_CFG6_NEG_STOP_TEMP * 1
609
610 // | GP22_CFG6_DOUBLE_RES * 1
612 // | GP22_CFG6_EN_ANALOG * 1
613 // | GP22_CFG6_TW2_0 * 3
615 // | GP22_CFG6_FIREO_DEF * 0
617 | GP22_Ids[6];
618
619#ifdef __DEBUG_GP22_ATY
620 printf("\r\nREGI - 0: %08X\r\nREGI - 1: %08X\r\nREGI - 2: %08X\
621 \r\nREGI - 3: %08X\r\nREGI - 4: %08X\r\nREGI - 5: %08X\r\nREGI - 6: %08X",
622 GP22_REG[0], GP22_REG[1], GP22_REG[2],
623 GP22_REG[3], GP22_REG[4], GP22_REG[5], GP22_REG[6]);
624#endif /* __DEBUG_GP22_ATY */
625
626 GP22_WriteReg(0x80, GP22_REG[0]);
627 GP22_WriteReg(0x81, GP22_REG[1]);
628 GP22_WriteReg(0x82, GP22_REG[2]);
629 GP22_WriteReg(0x83, GP22_REG[3]);
630 GP22_WriteReg(0x84, GP22_REG[4]);
631 GP22_WriteReg(0x85, GP22_REG[5]);
632 GP22_WriteReg(0x86, GP22_REG[6]);
633}
634
635uint8_t gp22StartTofFlag = 0;
636uint32_t tofValue[4] = {0};
637uint8_t GP22_StartTofUs_Digital(void)
638{
639 uint32_t tofReadValue[4] = {0};
640 uint32_t PW1ST_Value = 0;
641
642 gp22StartTofFlag = 1;
645 // GP22_WriteData(GP22_OPCODE_START_TOF2);
646 if(GP22_WaitInt(GP22_STEP_START_TOF) != 0) return 1;
647 gp22StartTofFlag = 0;
648
649 tofReadValue[0] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x00);
650 tofReadValue[1] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x01);
651 tofReadValue[2] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x02);
652 tofReadValue[3] = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x03);
653 tofValue[0] = tofReadValue[0];
654 tofValue[1] = tofReadValue[1];
655 tofValue[2] = tofReadValue[2];
656 tofValue[3] = tofReadValue[3];
657 PW1ST_Value = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x08);
658 PW1ST_Value = PW1ST_Value * 1;
659#ifdef __DEBUG_GP22_ATY
660 printf("\r\nSTOF - TOF reg: 0x%08X - 0x%08X - 0x%08X - 0x%08X",
661 tofReadValue[0], tofReadValue[1], tofReadValue[2], tofReadValue[3]);
662 printf("\r\nSTOF - TOF reg: %d - %d - %d - %d",
663 tofReadValue[0], tofReadValue[1], tofReadValue[2], tofReadValue[3]);
664 printf("\r\nSTOF - TOF reg: %.2f - %.2f - %.2f - %.2f",
665 (float)tofReadValue[0] / 65536, (float)tofReadValue[1] / 65536,
666 (float)tofReadValue[2] / 65536, (float)tofReadValue[3] / 65536);
667 printf("\r\nSTOF - PW1ST value: 0x%02X - %f",
668 PW1ST_Value, (float)(PW1ST_Value >> 24) / 128);
669#endif /* __DEBUG_GP22_ATY */
670
671 return 0;
672}
673
674
675// Mode 1
676/* Laser distance calc ***********************************************************/
677#elif defined(GP22_MEASURE_UsWave1MHz1)
678// ---------------------------------------------------
679// T_ref
680// Time_Value = ----------- * measured_RAW_Value
681// Cal2-Cal1
682// 3*10^8 m/s light speed(0.3m/ns)
683// ---------------------------------------------------
684uint8_t GP22_StartTofLaserCal(void)
685{
686 uint32_t tofValue = 0, calValue = 0;
687
688 GP22_WriteReg(0x80, GP22_REG[0]
689 | GP22_CFG0_CALIBRATE * 1);
690 GP22_WriteReg(0x82, GP22_REG[2]
693 | (GP22_CFG2_EN_INT_HITS * 1));
696 if(GP22_WaitInt(GP22_STEP_START_TOF) != 0) return 1;
697#ifdef __DEBUG_GP22_ATY
698 printf("\r\nTOF - Laser: Cal over");
699#endif /* __DEBUG_GP22_ATY */
700 GP22_WriteReg(0x82, GP22_REG[2]
708 // for(uint8_t i = 0; i < 2; i++){}
712 if(GP22_WaitInt(GP22_STEP_START_TOF) != 0) return 1;
714#ifdef __DEBUG_GP22_ATY
715 printf("\r\nTOF - Laser: 0x%08X - %d", tofValue, tofValue);
716#endif /* __DEBUG_GP22_ATY */
717 GP22_WriteReg(0x81, GP22_REG[1]
726 | GP22_CFG1_HIT2_0 * 6
727 | GP22_CFG1_HIT1_0 * 7); // Cal1 - Cal2, EN Stop2/Stop1 1 hit
728 calValue = GP22_ReadReg(GP22_OPCODE_READ_REG | 0x01);
729#ifdef __DEBUG_GP22_ATY
730 printf("\r\nTOF - Laser: 0x%08X - %d", calValue, calValue / 65536);
731 printf("\r\nTOF - Laser: %f ns - %f m",
732 (float)tofValue / ((float)calValue / 65536) * 16, // TODO: Time calculate wrong
733 (float)tofValue / ((float)calValue / 65536) * 16 * 0.23);
734#endif /* __DEBUG_GP22_ATY */
735
736 return 0;
737}
738
739void GP22_Process(uint32_t* gp22ProcessValue)
740{
741 if(!GP22_Step(GP22_STEP_RESET)
742 && !GP22_Step(GP22_STEP_SPI_TEST)
743 && !GP22_Step(GP22_STEP_REG_INIT)
744 && !GP22_Step(GP22_STEP_READ_ID)
745 && !GP22_Step(GP22_STEP_COMPARE_E2)
746 && !GP22_Step(GP22_STEP_START_TOF)
747 // && !GP22_Step(GP22_STEP_CALC_HSC)
748 // && !GP22_Step(GP22_STEP_START_TEMP)
749 )
750 {
751 // gp22ProcessValue[0] = tofValue[0];
752 // gp22ProcessValue[1] = tofValue[1];
753 // gp22ProcessValue[2] = tofValue[2];
754 // gp22ProcessValue[3] = tofValue[3];
755 }
757#ifdef __DEBUG_GP22_ATY
758 printf("\r\n");
759#endif /* __DEBUG_GP22_ATY */
760}
761#endif /* if defined*/
762
763
764
765
766
767
768
769
770
771#endif /* __GP22_ATY_C */
772
773/******************************** End Of File *********************************/
float ALGO_ResToKelvinTemp(float Rntc, float R25, float B)
Calculate temperature from ntc resistance.
float tempRealValue[2]
Definition: GP22_ATY.c:342
float speedWave[2]
Definition: GP22_ATY.c:345
void GP22_WriteData(uint8_t data_t)
write data with spi
Definition: GP22_ATY.c:44
void GP22_WriteReg(uint8_t opcode_address, uint32_t reg_data)
Definition: GP22_ATY.c:51
uint16_t GP22_AnalyseErrCode(void)
Definition: GP22_ATY.c:171
uint32_t GP22_REG[7]
Definition: GP22_ATY.c:339
uint8_t GP22_SpiTest(uint8_t data_t)
Definition: GP22_ATY.c:114
uint8_t GP22_Process_UsWave1MHz(uint8_t cmdCode)
Definition: GP22_ATY.c:507
uint8_t GP22_StartTof_UsWave1MHz(void)
Definition: GP22_ATY.c:456
uint32_t tofValue[4]
Definition: GP22_ATY.c:341
float echoTimeDetect[2]
Definition: GP22_ATY.c:343
uint8_t GP22_CompareE2(void)
Definition: GP22_ATY.c:210
uint16_t offsetValue
Definition: GP22_ATY.c:354
uint8_t GP22_WaitInt(uint8_t step)
Definition: GP22_ATY.c:94
uint32_t PW1ST_ValueA
Definition: GP22_ATY.c:346
float machineDelayTime
Definition: GP22_ATY.c:348
uint32_t GP22_ReadReg(uint8_t opcode_address)
Definition: GP22_ATY.c:64
float GP22_CALC_CLKHS_FREQ
Definition: GP22_ATY.c:337
uint16_t ignoreTime
Definition: GP22_ATY.c:353
uint8_t GP22_ReadId(void)
Definition: GP22_ATY.c:138
float usDistance
Definition: GP22_ATY.c:349
float echoTimeCalc[2]
Definition: GP22_ATY.c:344
void GP22_RegInit_UsWave1MHz(void)
Definition: GP22_ATY.c:364
uint8_t pulseNum
Definition: GP22_ATY.c:351
uint8_t GP22_CalcHSC(void)
Definition: GP22_ATY.c:246
void GP22_Reset(void)
Definition: GP22_ATY.c:82
uint8_t GP22_Process_Run(uint8_t cmdCode)
Definition: GP22_ATY.c:535
uint8_t firstWaveEnable
Definition: GP22_ATY.c:352
uint8_t GP22_StartTemp(void)
Definition: GP22_ATY.c:283
uint8_t GP22_Ids[8]
Definition: GP22_ATY.c:338
Base functions of GP22 for all embedded device.
#define GP22_CFG3FW_SEL_TIMO_MB2_0
Definition: GP22_ATY.h:369
#define GP22_STEP_START_TEMP
Definition: GP22_ATY.h:90
#define GP22_STEP_RESET
Definition: GP22_ATY.h:84
#define GP22_WAKE
Definition: GP22_ATY.h:116
#define GP22_CFG1_SEL_START_FIRE
Definition: GP22_ATY.h:224
#define GP22_CFG3FW_DELREL2_0
Definition: GP22_ATY.h:356
#define GP22_CFG5_DIS_PHASESHIFT
Definition: GP22_ATY.h:435
#define GP22_CFG1_SEL_TSTO2_0
Definition: GP22_ATY.h:221
#define GP22_CFG1_HIT1_3
Definition: GP22_ATY.h:237
#define GP22_CFG1_HIT2_1
Definition: GP22_ATY.h:239
#define GP22_CFG4FW_EDGE_FW
Definition: GP22_ATY.h:390
#define GP22_CFG3FW_EN_FIRST_WAVE
Definition: GP22_ATY.h:372
#define GP22_CFG3FW_DELREL3_0
Definition: GP22_ATY.h:362
#define GP22_OPCODE_COMPARE_E2
Definition: GP22_ATY.h:151
#define GP22_SIGNAL_H
Definition: GP22_ATY.h:93
#define GP22_CFG2_RFEDGE1
Definition: GP22_ATY.h:270
#define GP22_SIGNAL_L
Definition: GP22_ATY.h:94
#define GP22_CFG6_DA_KORR_0
Definition: GP22_ATY.h:466
#define GP22_CFG3FW_EN_AUTOCALC_MB2
Definition: GP22_ATY.h:373
#define GP22_CFG_KEEP_DEFAULT4
Definition: GP22_ATY.h:171
#define GP22_CFG4FW_DIS_PW
Definition: GP22_ATY.h:391
#define GP22_CLKHS_DIV
Definition: GP22_ATY.h:72
#define GP22_CLKHS_PERIOD
Definition: GP22_ATY.h:76
#define GP22_CFG1_HIT1_1
Definition: GP22_ATY.h:235
#define GP22_OPCODE_START_TOF
Definition: GP22_ATY.h:139
#define GP22_OPCODE_WRITE_E2
Definition: GP22_ATY.h:149
#define GP22_CFG6_EN_INT_END
Definition: GP22_ATY.h:462
#define GP22_RESET
Definition: GP22_ATY.h:111
#define GP22_CFG6_NEG_STOP_TEMP
Definition: GP22_ATY.h:471
#define GP22_REGADDR_STATUS
Definition: GP22_ATY.h:153
#define GP22_SIGNAL_A_H
Definition: GP22_ATY.h:95
#define GP22_STEP_START_TOF
Definition: GP22_ATY.h:91
#define GP22_CFG4FW_OFFSRNG1
Definition: GP22_ATY.h:388
#define GP22_STEP_SPI_TEST
Definition: GP22_ATY.h:85
#define GP22_CFG4FW_OFFS_0
Definition: GP22_ATY.h:383
#define GP22_OPCODE_READ_REG
Definition: GP22_ATY.h:147
#define GP22_CFG4FW_OFFSRNG2
Definition: GP22_ATY.h:389
#define GP22_DISABLE
Definition: GP22_ATY.h:110
#define GP22_STEP_COMPARE_E2
Definition: GP22_ATY.h:88
#define GP22_CFG1_SEL_TSTO1_0
Definition: GP22_ATY.h:218
#define GP22_CFG1_HITIN2_0
Definition: GP22_ATY.h:229
#define GP22_CFG_KEEP_DEFAULT5
Definition: GP22_ATY.h:172
#define GP22_CFG2_DELVAL1_0
Definition: GP22_ATY.h:251
#define GP22_CFG6_EN_ANALOG
Definition: GP22_ATY.h:472
#define GP22_CFG1_HIT2_2
Definition: GP22_ATY.h:240
#define GP22_CFG1_HIT2_3
Definition: GP22_ATY.h:241
#define GP22_CLKHS_FREQ
Definition: GP22_ATY.h:75
#define GP22_CFG1_HITIN1_0
Definition: GP22_ATY.h:226
#define GP22_CFG0_ANZ_PORT
Definition: GP22_ATY.h:194
#define GP22_ENABLE
Definition: GP22_ATY.h:109
#define GP22_READ_INT_H
Definition: GP22_ATY.h:113
#define GP22_CFG_KEEP_DEFAULT2
Definition: GP22_ATY.h:169
#define GP22_REGADDR_TEST
Definition: GP22_ATY.h:154
#define GP22_CFG6_ANZ_FIRE_END_0
Definition: GP22_ATY.h:449
#define GP22_OPCODE_RESET
Definition: GP22_ATY.h:138
#define GP22_CFG6_QUAD_RES
Definition: GP22_ATY.h:454
#define GP22_CFG0_ANZ_FIRE_0
Definition: GP22_ATY.h:205
#define GP22_CFG0_DIV_FIRE_0
Definition: GP22_ATY.h:201
#define GP22_CFG_KEEP_DEFAULT0
Definition: GP22_ATY.h:167
#define GP22_OPCODE_CALC_HSC
Definition: GP22_ATY.h:141
#define GP22_CFG0_MESSB2
Definition: GP22_ATY.h:188
#define GP22_STEP_READ_ID
Definition: GP22_ATY.h:87
#define GP22_CFG1_HIT2_0
Definition: GP22_ATY.h:238
#define GP22_NORESET
Definition: GP22_ATY.h:112
#define GP22_CFG3FW_EN_ERR_VAL
Definition: GP22_ATY.h:371
#define GP22_CFG_KEEP_DEFAULT3
Definition: GP22_ATY.h:170
#define GP22_CFG2_EN_INT_TDC_TIMEOUT
Definition: GP22_ATY.h:274
#define GP22_OPCODE_START_CAL_TOF
Definition: GP22_ATY.h:142
#define GP22_CFG1_HIT1_0
Definition: GP22_ATY.h:234
#define GP22_OPCODE_WRITE_REG
Definition: GP22_ATY.h:146
#define GP22_OPCODE_READ_ID
Definition: GP22_ATY.h:148
#define GP22_CFG0_SEL_ECLK_TEMP
Definition: GP22_ATY.h:191
#define GP22_TEMP_REF_RES
Definition: GP22_ATY.h:79
#define GP22_CFG3FW_DELREL1_0
Definition: GP22_ATY.h:350
#define GP22_CFG0_ANZ_FAKE
Definition: GP22_ATY.h:192
#define GP22_OPCODE_INIT
Definition: GP22_ATY.h:137
#define GP22_CFG0_TCYCLE
Definition: GP22_ATY.h:193
#define GP22_CFG0_CALIBRATE
Definition: GP22_ATY.h:190
#define GP22_CFG0_ANZ_PER_CALRES_0
Definition: GP22_ATY.h:199
#define GP22_CFG1_HIT1_2
Definition: GP22_ATY.h:236
#define GP22_SIGNAL_A_L
Definition: GP22_ATY.h:96
#define GP22_CFG5_PHFIRE_0
Definition: GP22_ATY.h:416
#define GP22_CFG_KEEP_DEFAULT6
Definition: GP22_ATY.h:173
#define GP22_CFG2_EN_INT_HITS
Definition: GP22_ATY.h:273
#define GP22_CFG0_START_CLKHS_0
Definition: GP22_ATY.h:195
#define GP22_CFG2_EN_INT_ALU
Definition: GP22_ATY.h:272
#define GP22_CFG5_CON_FIRE_DOWN
Definition: GP22_ATY.h:437
#define GP22_CFG5_EN_STARTNOISE
Definition: GP22_ATY.h:436
#define GP22_STEP_CALC_HSC
Definition: GP22_ATY.h:89
#define GP22_STEP_REG_INIT
Definition: GP22_ATY.h:86
#define GP22_CFG0_DIV_CLKHS_0
Definition: GP22_ATY.h:197
#define GP22_CFG_KEEP_DEFAULT1
Definition: GP22_ATY.h:168
#define GP22_OPCODE_START_TEMP
Definition: GP22_ATY.h:140
uint8_t SPI_Write(uint8_t *data_t, uint16_t len)
uint8_t SPI_Read(uint8_t *data_t, uint16_t len)
void DelayMs(uint32_t ms)
__WEAK_ATY void printf(uint8_t *,...)
unsigned long uint32_t
Definition: fw_types.h:20
unsigned short uint16_t
Definition: fw_types.h:19
unsigned char uint8_t
Definition: fw_types.h:18
uint8_t __XDATA i