/** ****************************************************************************** * @file stm32f0xx_it.c * @brief Interrupt Service Routines. ****************************************************************************** * * COPYRIGHT(c) 2017 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f0xx_hal.h" #include "stm32f0xx.h" #include "stm32f0xx_it.h" /* USER CODE BEGIN 0 */ #include "arm_math.h" __IO uint16_t data = 0; __IO uint16_t proud = 2400; arm_pid_instance_q15 pid_proud; /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ extern ADC_HandleTypeDef hadc; extern TIM_HandleTypeDef htim1; /******************************************************************************/ /* Cortex-M0 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); HAL_SYSTICK_IRQHandler(); /* USER CODE BEGIN SysTick_IRQn 1 */ /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ /* STM32F0xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32f0xx.s). */ /******************************************************************************/ /** * @brief This function handles ADC and COMP interrupts (COMP interrupts through EXTI lines 21 and 22). */ uint16_t adc[5]; int16_t pwm, err, reg; uint16_t index = 0; void ADC1_COMP_IRQHandler(void) { /* USER CODE BEGIN ADC1_COMP_IRQn 0 */ adc[index] = ADC1->DR; // nacteni hodnoty ADC index++; // inkrementace promenne pro dalsi mereni if(index >= 4){ // pri zmereni vsech hodnot -> vynuluj index mereni index = 0; } ADC1->ISR &= ~ADC_ISR_EOC; // nulovani znaku preruseni err = proud - adc; // vypocet chyby pro vstup PS regulatoru reg = arm_pid_q15(&pid_proud, err); // volani fce pro PS regulator //reg = err; //pwm = ((uint16_t)(reg + 32768UL) * 239UL) >> 16; pwm = ((reg * 120UL) >> 10) + 120; // prepocet precteneho proudu pro nastaveni nove stridy PWM if (pwm > 200) pwm = 200; // ochrana proti rozkmitani regulatoru -> nikdy nedojde k otevreni pouze horniho tranzistoru if (pwm < 0) pwm = 0; // pri spatne zpetne vazbe regulatoru je vypnut vystup -> dojde k uzemneni Q2 TIM1->CCR1 = pwm; // nastaveni nove vypoctene stridy data = (data*7 + adc) / 8; // filtrovani AD vstupu -> overeni dat pro DEBUG GPIOC->ODR ^= GPIO_PIN_8; // overeni spravneho volani preruseni -> slouzi pro overeni spravneho casovani /* USER CODE END ADC1_COMP_IRQn 0 */ HAL_ADC_IRQHandler(&hadc); // nastaveni volani preruseni pro dalsi mereni /* USER CODE BEGIN ADC1_COMP_IRQn 1 */ /* USER CODE END ADC1_COMP_IRQn 1 */ } /** * @brief This function handles TIM1 break, update, trigger and commutation interrupts. */ void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ TIM1->SR &= ~TIM_SR_UIF; // povoleni interrupt flagu -> moznost externe ridit periferie pomoci preruseni /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ HAL_TIM_IRQHandler(&htim1); /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/