ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
pwm_2ch_timer2_interrupt.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
23#include "fw_hal.h"
24
25__BIT dir = SET;
27
28INTERRUPT(Timer2_Routine, EXTI_VectTimer2)
29{
32 UART1_TxString("\r\n");
33 if (dir)
34 {
35 dc++;
36 if (dc == 0xFF) dir = !dir;
37 }
38 else
39 {
40 dc--;
41 if (dc == 0) dir = !dir;
42 }
43}
44
45void main(void)
46{
48 // UART1, baud 115200, baud source Timer1, 1T mode
50
51 // Set GPIO pins output mode
53 // Turn off PWMA.1 before change its mode
56 // Set PWMA.1 port direction output
58 // Set PWMA.1 output low voltage when counter is less than target value
60 // Enable comparison value preload to make duty cycle changing smooth
62 // Turn on PWMA.1
64 // Turn on PWMA.1 complementary output
66 // Set highest PWM clock
68 // PWM width = Period + 1 (side alignment), or AutoReloadPeriod * 2 (center alignment)
69 PWMA_SetPeriod(0xFF);
70 // Counter direction, down:from [PWMA_ARRH,PWMA_ARRL] to 0
72 // Enable preload on reload-period
74 // Enable output on PWMA.1P, PWMA.1N
76 // Set PWMA.1 alternative ports to P1.0 and P1.1
78 // Enable overall output
80 // Start counter
82
83 // 1T mode, prescaler:255+1, frequency: 100
85 // Timer2 interrupt: ON
89
90 while(1);
91}
#define EXTI_Timer2_SetIntState(__STATE__)
Definition: fw_exti.h:134
#define EXTI_Global_SetIntState(__STATE__)
Definition: fw_exti.h:115
#define EXTI_VectTimer2
Definition: fw_exti.h:49
@ GPIO_Pin_0
Definition: fw_gpio.h:45
@ GPIO_Pin_1
Definition: fw_gpio.h:46
#define GPIO_P1_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:79
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
#define PWMA_SetOverallState(__STATE__)
Definition: fw_pwm.h:102
#define PWMA_SetPinOutputState(__PINS__, __STATE__)
Definition: fw_pwm.h:105
#define PWMA_PWM1_SetPortState(__STATE__)
Definition: fw_pwm.h:159
#define PWMA_PWM1_SetPort(__ALTER_PORT__)
Definition: fw_pwm.h:291
#define PWMA_PWM1N_SetPortState(__STATE__)
Definition: fw_pwm.h:161
#define PWMA_PWM1_SetComparePreload(__STATE__)
Definition: fw_pwm.h:208
#define PWMA_PWM1_SetCaptureCompareValue(__16BIT_VAL__)
Definition: fw_pwm.h:232
#define PWMA_PWM1_SetPortDirection(__PORT_DIR__)
Definition: fw_pwm.h:190
@ PWM_OutputMode_PWM_LowIfLess
Definition: fw_pwm.h:71
#define PWMA_PWM1_ConfigOutputMode(__MODE__)
Definition: fw_pwm.h:216
#define PWMA_SetPrescaler(__16BIT_VAL__)
Definition: fw_pwm.h:87
@ PWMA_PWM1_AlterPort_P10_P11
Definition: fw_pwm.h:263
#define PWMA_SetAutoReloadPreload(__STATE__)
Definition: fw_pwm.h:122
#define PWMA_SetPeriod(__16BIT_VAL__)
Definition: fw_pwm.h:94
@ PWMB_PortDirOut
Definition: fw_pwm.h:407
#define PWMA_SetCounterDirection(__DIR__)
Definition: fw_pwm.h:135
@ PWM_CounterDirection_Down
Definition: fw_pwm.h:56
@ PWM_Pin_1N
Definition: fw_pwm.h:25
@ PWM_Pin_1
Definition: fw_pwm.h:24
#define PWMA_SetCounterState(__STATE__)
Definition: fw_pwm.h:154
void SYS_SetClock(void)
Definition: fw_sys.c:40
#define TIM_Timer2_SetRunState(__STATE__)
Definition: fw_tim.h:75
void TIM_Timer2_Config(HAL_State_t freq1t, uint8_t prescaler, uint16_t frequency)
Definition: fw_tim.c:93
@ HAL_State_OFF
Definition: fw_types.h:70
@ HAL_State_ON
Definition: fw_types.h:71
@ SET
Definition: fw_types.h:85
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer1
Definition: fw_uart.h:33
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
INTERRUPT(Timer2_Routine, EXTI_VectTimer2)
uint8_t dc
void main(void)