Hallo zusammen, ich habe das Problem, dass bei der Übernahme eines neuen Tastverhältnisses die aktuelle Periode unterbrochen wird - und dadurch ein falsches PWM-Verhältnis zwischen altem und neuem PWM Signal entsteht. Wie kann ich sicherstellen, dass die derzeitige Periode vollständig ist, ehe die neuen Werte übernommen werden. Danke + Gruß Stefan PS: Verwendeter Code ungefähr identisch mit dem von Niklas Gürtler (STM32 Servoansteuerung PWM) vom 21.01.2012 // TimeBase TIM_TimeBaseInitTypeDef timBase; TIM_TimeBaseStructInit (&timBase); timBase.TIM_Prescaler = ((SystemCoreClock / 2 ) / 1000000)-1; timBase.TIM_ClockDivision = TIM_CKD_DIV1; timBase.TIM_CounterMode = TIM_CounterMode_Up; timBase.TIM_Period = 20000; TIM_TimeBaseInit (TIM4, &timBase); TIM_ARRPreloadConfig (TIM4, ENABLE); // Update registers TIM4->EGR |= (1 << TIM_EGR_UG); // Output compare match TIM_OCInitTypeDef oc; TIM_OCStructInit (&oc); oc.TIM_OCIdleState = TIM_OCIdleState_Reset; oc.TIM_OCNIdleState = TIM_OCNIdleState_Set; oc.TIM_OCMode = TIM_OCMode_PWM1; oc.TIM_OCPolarity = TIM_OCPolarity_High; oc.TIM_OutputState = TIM_OutputState_Enable; oc.TIM_Pulse = 1500; // Initiale Pulsweite in Millisekunden TIM_OC1Init (TIM4, &oc); TIM_OC1PreloadConfig (TIM4, TIM_OCPreload_Enable); TIM_BDTRInitTypeDef bdtr; TIM_BDTRStructInit (&bdtr); bdtr.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; TIM_BDTRConfig (TIM4, &bdtr); // Start the timer TIM_Cmd (TIM4, ENABLE); // Configure GPIO Pin RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIODEN, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig (GPIOD, GPIO_PinSource12, GPIO_AF_TIM4); // Ändern der Pulsweite: TIM_SetCompare1 (TIM4, 1500); // Pulsweite in Millisekunden
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.