ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
pwm_2ch_complementary.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
26void main(void)
27{
28 __BIT dir = SET;
29 uint8_t dc = 0;
30
32 // UART1, baud 115200, baud source Timer2, 1T mode
34
35 // Set GPIO pins output mode
37 // Turn off PWMA.1 before change its mode
40 // Set PWMA.1 port direction output
42 // Set PWMA.1 output low voltage when counter is less than target value
44 // Enable comparison value preload to make duty cycle changing smooth
46 // Turn on PWMA.1
48 // Turn on PWMA.1 complementary output
50 // Set highest PWM clock
52 // PWM width = Period + 1 (side alignment), or AutoReloadPeriod * 2 (center alignment)
53 PWMA_SetPeriod(0xFF);
54 // Counter direction, down:from [PWMA_ARRH,PWMA_ARRL] to 0
56 // Enable preload on reload-period
58 // Enable output on PWMA.1P, PWMA.1N
60 // Set PWMA.1 alternative ports to P1.0 and P1.1
62 // Enable overall output
64 // Start counter
66
67 while(1)
68 {
70 UART1_TxHex(0xFF);
71 if (dir)
72 {
73 dc++;
74 if (dc == 0xFF) dir = !dir;
75 }
76 else
77 {
78 dc--;
79 if (dc == 0) dir = !dir;
80 }
81 UART1_TxString("\r\n");
82 SYS_Delay(10);
83 }
84}
@ 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
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ 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_Timer2
Definition: fw_uart.h:34
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
uint16_t dc
__BIT dir
void main(void)