collab/mm20
git clone https://git.julia.blue/collab/mm20
d410890
firmware
1#include "motors.h" 2#include "tivaware/gpio.h" 3#include "tivaware/hw_memmap.h" 4#include "tivaware/pin_map.h" 5#include "tivaware/qei.h" 6#include "tivaware/rom.h" 7#include "tivaware/sysctl.h" 8/* XDCtools Header files */ 9#include <xdc/std.h> 10#include <xdc/runtime/System.h> 11 12/* BIOS Header files */ 13#include <ti/sysbios/BIOS.h> 14#include <ti/sysbios/knl/Task.h> 15 16/* TI-RTOS Header files */ 17#include <ti/drivers/GPIO.h> 18#include <ti/drivers/PWM.h> 19 20/* Example/Board Header files */ 21#include "Board.h" 22 23// TODO: init pwm for drivers 24void init_motors () { 25ROM_SysCtlPeripheralEnable (SYSCTL_PERIPH_QEI0 ); 26ROM_SysCtlPeripheralEnable (SYSCTL_PERIPH_QEI1 ); 27ROM_SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOC ); 28ROM_SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOD ); 29ROM_GPIOPinConfigure (GPIO_PD6_PHA0 ); 30ROM_GPIOPinConfigure (GPIO_PD7_PHB0 ); 31ROM_GPIOPinConfigure (GPIO_PC5_PHA1 ); 32ROM_GPIOPinConfigure (GPIO_PC6_PHB1 ); 33ROM_GPIOPinTypeQEI (GPIO_PORTD_BASE ,GPIO_PIN_6 |GPIO_PIN_7 ); 34ROM_GPIOPinTypeQEI (GPIO_PORTC_BASE ,GPIO_PIN_5 |GPIO_PIN_6 ); 35ROM_QEIConfigure (QEI0_BASE ,QEI_CONFIG_CAPTURE_A_B |QEI_CONFIG_SWAP , 36UINT32_MAX ); 37ROM_QEIConfigure (QEI1_BASE ,QEI_CONFIG_CAPTURE_A_B |QEI_CONFIG_NO_SWAP , 38UINT32_MAX ); 39ROM_QEIVelocityConfigure (QEI0_BASE ,QEI_VELDIV_1 ,VELOCITY_PERIOD ); 40ROM_QEIVelocityConfigure (QEI1_BASE ,QEI_VELDIV_1 ,VELOCITY_PERIOD ); 41ROM_QEIEnable (QEI0_BASE ); 42ROM_QEIEnable (QEI1_BASE ); 43ROM_QEIVelocityEnable (QEI0_BASE ); 44ROM_QEIVelocityEnable (QEI1_BASE ); 45} 46 47int32_t left_pos (void ) { 48return ROM_QEIPositionGet (QEI0_BASE ); 49} 50 51int32_t right_pos (void ) { 52return ROM_QEIPositionGet (QEI1_BASE ); 53} 54 55uint32_t left_speed (void ) { 56return ROM_QEIVelocityGet (QEI0_BASE ); 57} 58uint32_t right_speed (void ) { 59return ROM_QEIVelocityGet (QEI1_BASE ); 60} 61 62void reset_enc (void ) { 63ROM_QEIPositionSet (QEI0_BASE ,0 ); 64ROM_QEIPositionSet (QEI1_BASE ,0 ); 65} 66 67Void pwmMotorFxn (UArg arg0 ,UArg arg1 )//this is currently a copy pasted LED example renamed to Motor 68{ 69PWM_Handle pwm1 ; 70PWM_Handle pwm2 = NULL ; 71PWM_Params params ; 72uint16_t pwmPeriod = 3000 ;// Period and duty in microseconds 73uint16_t duty = 0 ; 74uint16_t dutyInc = 100 ; 75 76PWM_Params_init (& params ); 77params .period = pwmPeriod ; 78pwm1 = PWM_open (Board_PWM0 ,& params ); 79if (pwm1 == NULL ) { 80System_abort ("Board_PWM0 did not open" ); 81 } 82 83if (Board_PWM1 != Board_PWM0 ) { 84params .polarity = PWM_POL_ACTIVE_LOW ; 85pwm2 = PWM_open (Board_PWM1 ,& params ); 86if (pwm2 == NULL ) { 87System_abort ("Board_PWM1 did not open" ); 88 } 89 } 90 91/* Loop forever incrementing the PWM duty */ 92while (1 ) { 93PWM_setDuty (pwm1 ,duty ); 94 95if (pwm2 ) { 96PWM_setDuty (pwm2 ,duty ); 97 } 98 99duty = (duty + dutyInc ); 100if (duty == pwmPeriod || (!duty )) { 101dutyInc = - dutyInc ; 102 } 103 104Task_sleep ((UInt )arg0 ); 105 } 106} 107 108 109void set_left (float speed ) { 110// TODO 111} 112 113void set_right (float speed ) { 114// TODO 115}