ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
main.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
22#include "fw_hal.h"
23#include "voice.h"
24
27
29{
30 // Set GPIO pins output mode P10 -> PWMA.1P
32 // Turn off PWMA.1 before change its mode
35 // Set PWMA.1 port direction output
37 // Set PWMA.1 output low voltage when counter is less than target value
39 // Enable comparison value preload to make duty cycle changing smooth
41 // Turn on PWMA.1
43
44 // Set PWM frequency to 16kHz, Fpwm = SYSCLK / (PWMx_PSCR + 1) / (PWMx_ARR + 1)
45 // You will hear obvious noise if PWM frequency is less than 12kHz
47 // PWM width = Period + 1 (side alignment), or AutoReloadPeriod * 2 (center alignment)
48 PWMA_SetPeriod(0xFF);
49 // Counter direction, down:from [PWMA_ARRH,PWMA_ARRL] to 0
51 // Enable preload on reload-period
53 // Enable output on PWMA.1P
55 // Set PWMA.1 alternative ports to P1.0 and P1.1
57 // Enable overall output
59 // Start counter
61}
62
64{
70}
71
72INTERRUPT(Timer0_Routine, EXTI_VectTimer0)
73{
74 uint8_t dc;
77 if (voice_pos == voice_size) voice_pos = 0;
78}
79
80void main(void)
81{
83 PWM_Init();
85
86 while(1);
87}
#define EXTI_Timer0_SetIntPriority(__PRIORITY__)
Definition: fw_exti.h:214
@ EXTI_IntPriority_High
Definition: fw_exti.h:25
#define EXTI_Timer0_SetIntState(__STATE__)
Definition: fw_exti.h:116
#define EXTI_Global_SetIntState(__STATE__)
Definition: fw_exti.h:115
#define EXTI_VectTimer0
Definition: fw_exti.h:38
@ GPIO_Pin_0
Definition: fw_gpio.h:45
#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_HighIfLess
Definition: fw_pwm.h:70
#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_1
Definition: fw_pwm.h:24
#define PWMA_SetCounterState(__STATE__)
Definition: fw_pwm.h:154
void SYS_SetClock(void)
Definition: fw_sys.c:40
@ TIM_TimerMode_16BitAuto
Definition: fw_tim.h:24
void TIM_Timer0_Config(HAL_State_t freq1t, TIM_TimerMode_t mode, uint16_t frequency)
Definition: fw_tim.c:38
#define TIM_Timer0_SetRunState(__STATE__)
Definition: fw_tim.h:35
unsigned short uint16_t
Definition: fw_types.h:19
@ HAL_State_OFF
Definition: fw_types.h:70
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
int main(void)
Definition: main.c:45
INTERRUPT(Timer0_Routine, EXTI_VectTimer0)
Definition: main.c:72
uint8_t dc
Definition: main.c:25
void Timer0_Init()
Definition: main.c:63
uint16_t voice_size
Definition: main.c:26
uint16_t voice_pos
Definition: main.c:26
void PWM_Init()
Definition: main.c:28
__CODE uint8_t voice_bulk[]
Definition: voice.c:3