Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* My Exact Header File For Motor Control
- Sean O'Keefe
- 4/17/2015
- ELEC471-02
- Embedded Computer Systems Final
- */
- #ifndef MOTORCONTROL_H
- #define MOTORCONTROL_H
- //Define motor speed values for the Comparator register to match with the timer
- //100 steps = 6250 0x186A
- #define Step_MaxH 0X18
- #define Step_MaxL 0X6A
- //90 steps = 6944 0X1B20
- #define Step_EightH 0X1B
- #define Step_EightL 0X20
- //80 steps = 7813 0X1E85
- #define Step_SevenH 0X1E
- #define Step_SevenL 0X85
- //70 steps = 8929 0X22E1
- #define Step_SixH 0X22
- #define Step_SixL 0XE1
- //60 steps = 10417 0X28B1
- #define Step_FiveH 0X28
- #define Step_FiveL 0XB1
- //50 steps = 12500 0X30D4
- #define Step_FourH 0X30
- #define Step_FourL 0XD4
- //40 steps = 15625 0X3D09
- #define Step_ThreeH 0X3D
- #define Step_ThreeL 0X09
- //30 steps = 20833 0X5161
- #define Step_TwoH 0X51
- #define Step_TwoL 0X61
- //25 steps = 25000 0X61A8
- #define Step_MinH 0X61
- #define Step_MinL 0XA8
- //Function for speed control where speed is the value stored from the keypad read in my previous post
- int Change_Speed(int Speed){
- if(1 == Speed)
- {
- CCPR1H = Step_MinH; //These are the registers the comparator matches to the timer1
- CCPR1L = Step_MinL; //if timer register == the value on these two the interrupt is called and timer is reset
- } //See the port set up pastebin for the interrupt function, all it does is toggle a port High or low
- if(2 == Speed)
- {
- CCPR1H = Step_TwoH;
- CCPR1L = Step_TwoL;
- }
- if(3 == Speed)
- {
- CCPR1H = Step_ThreeH;
- CCPR1L = Step_ThreeL;
- }
- if(4 == Speed)
- {
- CCPR1H = Step_FourH;
- CCPR1L = Step_FourL;
- }
- if(5 == Speed)
- {
- CCPR1H = Step_FiveH;
- CCPR1L = Step_FiveL;
- }
- if(6 == Speed)
- {
- CCPR1H = Step_SixH;
- CCPR1L = Step_SixL;
- }
- if(7 == Speed)
- {
- CCPR1H = Step_SevenH;
- CCPR1L = Step_SevenL;
- }
- if(8 == Speed)
- {
- CCPR1H = Step_EightH;
- CCPR1L = Step_EightL;
- }
- if(9 == Speed)
- {
- CCPR1H = Step_MaxH;
- CCPR1L = Step_MaxL;
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement