AfInit.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //********************************************************************************
  2. //
  3. // LC89821x Initialize Module
  4. //
  5. // Program Name : AfInit.h
  6. // Design : Rex.Tang
  7. // History : First edition 2013.07.20 Rex.Tang
  8. //
  9. // Description : AF Initialize Functions and Definations
  10. //********************************************************************************
  11. //**************************
  12. // Include Header File
  13. //**************************
  14. #include "AfInit.h"
  15. #include "AfData.h"
  16. /*-----------------------------
  17. Definations
  18. ------------------------------*/
  19. #define REG_ADDR_START 0x80 // REG Start address
  20. /*====================================================================
  21. Interface functions (import)
  22. =====================================================================*/
  23. extern void RamWriteA(unsigned short addr, unsigned short data);
  24. extern void RamReadA(unsigned short addr, unsigned short *data);
  25. extern void RegWriteA(unsigned short addr, unsigned char data);
  26. extern void RegReadA(unsigned short addr, unsigned char *data);
  27. extern void WaitTime(unsigned short msec);
  28. //********************************************************************************
  29. // Function Name : AfInit
  30. // Retun Value : NON
  31. // Argment Value : Hall Bias, Hall Offset
  32. // Explanation : Af Initial Function
  33. // History : First edition 2013.07.20 Rex.Tang
  34. //********************************************************************************
  35. void AfInit( unsigned char hall_off, unsigned char hall_bias )
  36. {
  37. #define DataLen sizeof(Init_Table) / sizeof(IniData)
  38. unsigned short i;
  39. unsigned short pos;
  40. for(i = 0; i < DataLen; i++)
  41. {
  42. if(Init_Table[i].addr == WAIT)
  43. {
  44. WaitTime(Init_Table[i].data);
  45. continue;
  46. }
  47. if(Init_Table[i].addr >= REG_ADDR_START)
  48. {
  49. RegWriteA(Init_Table[i].addr, (unsigned char)(Init_Table[i].data & 0x00ff));
  50. } else {
  51. RamWriteA(Init_Table[i].addr, (unsigned short)Init_Table[i].data);
  52. }
  53. }
  54. RegWriteA( 0x28, hall_off); // Hall Offset
  55. RegWriteA( 0x29, hall_bias); // Hall Bias
  56. RamReadA( 0x3C, &pos);
  57. RamWriteA( 0x04, pos); // Direct move target position
  58. RamWriteA( 0x18, pos); // Step move start position
  59. //WaitTime(5);
  60. //RegWriteA( 0x87, 0x85 ); // Servo ON
  61. }
  62. //********************************************************************************
  63. // Function Name : ServoON
  64. // Retun Value : NON
  65. // Argment Value : None
  66. // Explanation : Servo On function
  67. // History : First edition 2013.07.20 Rex.Tang
  68. //********************************************************************************
  69. void ServoOn(void)
  70. {
  71. RegWriteA( 0x85, 0x80); // Clear PID Ram Data
  72. WaitTime(1);
  73. RegWriteA( 0x87, 0x85 ); // Servo ON
  74. }