both motors
This commit is contained in:
@@ -40,27 +40,37 @@ void InitDoneCallback(void * p_arg) {
|
||||
|
||||
timer_Init();
|
||||
|
||||
uint16_t melody[][2] = {{440, 500}, {440, 500}, {440, 500}, {349, 350}, {523, 150}, {440, 500}, {349, 350}, {523, 150}, {440, 1000}, {659, 500}, {659, 500}, {659, 500}, {698, 350}, {523, 150}, {415, 500}, {349, 350}, {523, 150}, {440, 1000}};
|
||||
|
||||
while(1){
|
||||
for(int16_t i = -1000; i<=1000; i++){
|
||||
for(uint8_t i=0; i<(sizeof(melody)/sizeof(melody[0])); i++){
|
||||
CPU_SR cpu_sr;
|
||||
OS_ENTER_CRITICAL();
|
||||
// This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
pidValue = i;
|
||||
pidValue = melody[i][0];
|
||||
OS_EXIT_CRITICAL();
|
||||
timer_Task(0);
|
||||
//UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
OSTimeDly(1);
|
||||
}
|
||||
for(int16_t i = 1000; i>=-1000; i--){
|
||||
CPU_SR cpu_sr;
|
||||
OS_ENTER_CRITICAL();
|
||||
// This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
pidValue = i;
|
||||
timer_Task(0);
|
||||
OS_EXIT_CRITICAL();
|
||||
//UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
OSTimeDly(1);
|
||||
OSTimeDly(melody[i][1]);
|
||||
}
|
||||
//for(int16_t i = -1000; i<=1000; i++){
|
||||
// CPU_SR cpu_sr;
|
||||
// OS_ENTER_CRITICAL();
|
||||
// // This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
// pidValue = i;
|
||||
// OS_EXIT_CRITICAL();
|
||||
// timer_Task(0);
|
||||
// //UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
// OSTimeDly(1);
|
||||
//}
|
||||
//for(int16_t i = 1000; i>=-1000; i--){
|
||||
// CPU_SR cpu_sr;
|
||||
// OS_ENTER_CRITICAL();
|
||||
// // This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
// pidValue = i;
|
||||
// timer_Task(0);
|
||||
// OS_EXIT_CRITICAL();
|
||||
// //UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
// OSTimeDly(1);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ static void motor_Set_Steering_Direction(uint8_t steeringDirection, int16_t *mot
|
||||
static void motor_Set_Moving_Direction (u32 pin, int16_t value);
|
||||
static void timer_gpio_Init();
|
||||
|
||||
XTtcPs xttcps;
|
||||
XTtcPs_Config* TimerSetup;
|
||||
XTtcPs xttcps[2];
|
||||
|
||||
XGpioPs xgpiops;
|
||||
XGpioPs_Config* gpioCfg;
|
||||
@@ -33,14 +32,18 @@ extern int16_t pidValue;
|
||||
|
||||
void timer_Task(void *pdata) {
|
||||
if(pidValue){
|
||||
uint16_t interval = (64000/abs(pidValue));
|
||||
uint16_t interval = 1.337*(64000/abs(pidValue));
|
||||
uint8_t direction = pidValue<0;
|
||||
//UCOS_Printf("%d %d\r\n", direction, interval);
|
||||
//UCOS_Printf("counter value: %d\r\n", XTtcPs_GetCounterValue(&xttcps));
|
||||
timer_Stop(0);
|
||||
timer_Stop(1);
|
||||
timer_Set_Interval_Length(0,interval);
|
||||
timer_Set_Interval_Length(1,interval);
|
||||
timer_Start(0);
|
||||
timer_Start(1);
|
||||
motor_Set_Moving_Direction(54, direction);
|
||||
motor_Set_Moving_Direction(55, !direction);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -51,12 +54,8 @@ void timer_Task(void *pdata) {
|
||||
/* * * intializes and starts two timers with respective puls generation on gpio pins * * */
|
||||
int timer_Init(){
|
||||
UCOS_Print("Setting up Timer!\r\n");
|
||||
TimerSetup = XTtcPs_LookupConfig(XPAR_PS7_TTC_0_DEVICE_ID);
|
||||
XTtcPs_CfgInitialize(&xttcps, TimerSetup, TimerSetup->BaseAddress);
|
||||
XTtcPs_SetOptions(&xttcps, XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_MATCH_MODE);
|
||||
XTtcPs_SetPrescaler(&xttcps, 8);
|
||||
XTtcPs_SetMatchValue(&xttcps, 0, 1);
|
||||
XTtcPs_SetInterval(&xttcps, 2);
|
||||
|
||||
timer_Dual_Timer_Setup();
|
||||
|
||||
timer_gpio_Init();
|
||||
motor_Set_Moving_Direction(54, 1);
|
||||
@@ -85,30 +84,36 @@ static void timer_gpio_Init(){
|
||||
/* * * * * * sets up two timers by calling timer_Setup() for each wheel, connects and activates an interrupt to one of timers * * */
|
||||
static int timer_Dual_Timer_Setup(void)
|
||||
{
|
||||
|
||||
timer_Setup(XPAR_PS7_TTC_0_DEVICE_ID);
|
||||
timer_Setup(XPAR_PS7_TTC_1_DEVICE_ID);
|
||||
}
|
||||
|
||||
/* * * * * * sets up a timer counter device, initialize device, set options, set interval and prescaler value for given output frequency * * */
|
||||
static int timer_Setup(int DeviceID)
|
||||
{
|
||||
|
||||
XTtcPs_Config* TimerSetup = XTtcPs_LookupConfig(DeviceID);
|
||||
XTtcPs_CfgInitialize(&xttcps[DeviceID], TimerSetup, TimerSetup->BaseAddress);
|
||||
XTtcPs_SetOptions(&xttcps[DeviceID], XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_MATCH_MODE);
|
||||
XTtcPs_SetPrescaler(&xttcps[DeviceID], 8);
|
||||
XTtcPs_SetMatchValue(&xttcps[DeviceID], 0, 1);
|
||||
XTtcPs_SetInterval(&xttcps[DeviceID], 2);
|
||||
}
|
||||
|
||||
/* * * starts timer number "Id" * * */
|
||||
static void timer_Start(uint32_t Id){
|
||||
XTtcPs_Start(&xttcps);
|
||||
XTtcPs_Start(&xttcps[Id]);
|
||||
}
|
||||
|
||||
/* * * stops timer number "Id" * * */
|
||||
static void timer_Stop(uint32_t Id){
|
||||
XTtcPs_Stop(&xttcps);
|
||||
XTtcPs_Stop(&xttcps[Id]);
|
||||
}
|
||||
|
||||
|
||||
/* * * sets new interval length and the correct matchvalue * * */
|
||||
static void timer_Set_Interval_Length(uint32_t Id, uint16_t interval_length){
|
||||
if(XTtcPs_GetCounterValue(&xttcps) >= interval_length)
|
||||
XTtcPs_ResetCounterValue(&xttcps);
|
||||
XTtcPs_SetMatchValue(&xttcps, 0, interval_length/2);
|
||||
XTtcPs_SetInterval(&xttcps, interval_length);
|
||||
if(XTtcPs_GetCounterValue(&xttcps[Id]) >= interval_length)
|
||||
XTtcPs_ResetCounterValue(&xttcps[Id]);
|
||||
XTtcPs_SetMatchValue(&xttcps[Id], 0, interval_length/2);
|
||||
XTtcPs_SetInterval(&xttcps[Id], interval_length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user