This commit is contained in:
sdes1
2025-11-11 13:50:00 +01:00
parent cae559a7be
commit f18a2e4fb5
2 changed files with 31 additions and 35 deletions

View File

@@ -27,28 +27,22 @@ void InitDoneCallback(void * p_arg) {
(void) p_arg; (void) p_arg;
UCOS_Print("OS started!\r\n"); UCOS_Print("OS started!\r\n");
//OSTaskCreateExt(timer_Task, OSTaskCreateExt(timer_Task,
// 0, 0,
// &TimerStk[TIMER_STK_SIZE-1], &TimerStk[TIMER_STK_SIZE-1],
// TIMER_PRIO, TIMER_PRIO,
// TIMER_PRIO, TIMER_PRIO,
// &TimerStk[0], &TimerStk[0],
// TIMER_STK_SIZE, TIMER_STK_SIZE,
// 0, 0,
// 0 0
// ); );
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}}; 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){ while(1){
for(uint8_t i=0; i<(sizeof(melody)/sizeof(melody[0])); i++){ for(uint8_t i=0; i<(sizeof(melody)/sizeof(melody[0])); i++){
CPU_SR cpu_sr;
OS_ENTER_CRITICAL();
pidValue = melody[i][0]; pidValue = melody[i][0];
OS_EXIT_CRITICAL();
timer_Task(0);
OSTimeDly(melody[i][1]); OSTimeDly(melody[i][1]);
} }
//for(int16_t i = -1000; i<=1000; i++){ //for(int16_t i = -1000; i<=1000; i++){

View File

@@ -31,23 +31,27 @@ XGpioPs_Config* gpioCfg;
extern int16_t pidValue; extern int16_t pidValue;
void timer_Task(void *pdata) { void timer_Task(void *pdata) {
if(pidValue){ timer_Init();
uint16_t interval = 1.337*(64000/abs(pidValue));
uint8_t direction = pidValue<0; while(1){
//UCOS_Printf("%d %d\r\n", direction, interval); if(pidValue){
//UCOS_Printf("counter value: %d\r\n", XTtcPs_GetCounterValue(&xttcps)); uint16_t interval = 1.337*(64000/abs(pidValue));
timer_Stop(0); uint8_t direction = pidValue<0;
timer_Stop(1); //UCOS_Printf("%d %d\r\n", direction, interval);
timer_Set_Interval_Length(0,interval); //UCOS_Printf("counter value: %d\r\n", XTtcPs_GetCounterValue(&xttcps));
timer_Set_Interval_Length(1,interval); timer_Stop(0);
timer_Start(0); timer_Stop(1);
timer_Start(1); timer_Set_Interval_Length(0,interval);
motor_Set_Moving_Direction(54, direction); timer_Set_Interval_Length(1,interval);
motor_Set_Moving_Direction(55, !direction); timer_Start(0);
} timer_Start(1);
else motor_Set_Moving_Direction(54, direction);
{ motor_Set_Moving_Direction(55, !direction);
timer_Stop(0); }
else
{
timer_Stop(0);
}
} }
} }
@@ -56,9 +60,7 @@ int timer_Init(){
UCOS_Print("Setting up Timer!\r\n"); UCOS_Print("Setting up Timer!\r\n");
timer_Dual_Timer_Setup(); timer_Dual_Timer_Setup();
timer_gpio_Init(); timer_gpio_Init();
motor_Set_Moving_Direction(54, 1);
UCOS_Print("Done!\r\n"); UCOS_Print("Done!\r\n");
return 0; return 0;