Advertisement
Guest User

PIC16F877A Stepper Motor Control

a guest
Apr 20th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /* My Exact Header File For Motor Control
  2. Sean O'Keefe
  3. 4/17/2015
  4. ELEC471-02
  5. Embedded Computer Systems Final
  6. */
  7. #ifndef MOTORCONTROL_H
  8. #define MOTORCONTROL_H
  9. //Define motor speed values for the Comparator register to match with the timer
  10. //100 steps = 6250 0x186A
  11. #define Step_MaxH 0X18
  12. #define Step_MaxL 0X6A
  13. //90 steps = 6944 0X1B20
  14. #define Step_EightH 0X1B
  15. #define Step_EightL 0X20
  16. //80 steps = 7813 0X1E85
  17. #define Step_SevenH 0X1E
  18. #define Step_SevenL 0X85
  19. //70 steps = 8929 0X22E1
  20. #define Step_SixH 0X22
  21. #define Step_SixL 0XE1
  22. //60 steps = 10417 0X28B1
  23. #define Step_FiveH 0X28
  24. #define Step_FiveL 0XB1
  25. //50 steps = 12500 0X30D4
  26. #define Step_FourH 0X30
  27. #define Step_FourL 0XD4
  28. //40 steps = 15625 0X3D09
  29. #define Step_ThreeH 0X3D
  30. #define Step_ThreeL 0X09
  31. //30 steps = 20833 0X5161
  32. #define Step_TwoH 0X51
  33. #define Step_TwoL 0X61
  34. //25 steps = 25000 0X61A8
  35. #define Step_MinH 0X61
  36. #define Step_MinL 0XA8
  37.  
  38. //Function for speed control where speed is the value stored from the keypad read in my previous post
  39. int Change_Speed(int Speed){
  40. if(1 == Speed)
  41. {
  42. CCPR1H = Step_MinH; //These are the registers the comparator matches to the timer1
  43. CCPR1L = Step_MinL; //if timer register == the value on these two the interrupt is called and timer is reset
  44. } //See the port set up pastebin for the interrupt function, all it does is toggle a port High or low
  45.  
  46. if(2 == Speed)
  47. {
  48. CCPR1H = Step_TwoH;
  49. CCPR1L = Step_TwoL;
  50. }
  51.  
  52. if(3 == Speed)
  53. {
  54. CCPR1H = Step_ThreeH;
  55. CCPR1L = Step_ThreeL;
  56. }
  57.  
  58. if(4 == Speed)
  59. {
  60. CCPR1H = Step_FourH;
  61. CCPR1L = Step_FourL;
  62. }
  63.  
  64. if(5 == Speed)
  65. {
  66. CCPR1H = Step_FiveH;
  67. CCPR1L = Step_FiveL;
  68. }
  69.  
  70. if(6 == Speed)
  71. {
  72. CCPR1H = Step_SixH;
  73. CCPR1L = Step_SixL;
  74. }
  75.  
  76. if(7 == Speed)
  77. {
  78. CCPR1H = Step_SevenH;
  79. CCPR1L = Step_SevenL;
  80. }
  81.  
  82. if(8 == Speed)
  83. {
  84. CCPR1H = Step_EightH;
  85. CCPR1L = Step_EightL;
  86. }
  87. if(9 == Speed)
  88. {
  89. CCPR1H = Step_MaxH;
  90. CCPR1L = Step_MaxL;
  91. }
  92.  
  93. }
  94.  
  95. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement