Louie NRT Story

[Firmware] M058 - PWM 본문

스마트홈

[Firmware] M058 - PWM

hyeok0724.kim@gmail.com 2019. 5. 3. 16:03
반응형

[설명]

- pin24에 LED를 연결함

- PWM0 ~ PWM7 이 존재함

- 2개씩 묶어서 PWM0, PWM1 은 channel10, PWM2, PWM3은 channel11 으로 관리함

- PWMA -> PWM0 ~ PWM3, PWMB -> PWM4 ~ PWM7 로 관리됨

- PWMA의 0번은 PWM0 이고 PWMB의 0번은 PWM4 를 가르킴

- 기본적으로 PWM_ConfigOutputChannel 함수의 맨 끝에 60 값 바꾸면 조절됨

 

[기본코드]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include "M051Series.h"
 
#define PLLCON_SETTING      CLK_PLLCON_50MHz_HXT
#define PLL_CLOCK           50000000
 
void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Enable Internal RC clock */
    CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
 
    /* Waiting for IRC22M clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
 
    /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
 
    /* Enable PLL and Set PLL frequency */
    CLK_SetCoreClock(PLLCON_SETTING);
 
    /* Waiting for clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk | CLK_CLKSTATUS_OSC22M_STB_Msk);
 
    /* Switch HCLK clock source to PLL, STCLK to HCLK/2 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(2));
 
    /* Enable PWM module clock */
    CLK_EnableModuleClock(PWM45_MODULE);
 
    /* Select PWM module clock source */
    CLK_SetModuleClock(PWM23_MODULE, CLK_CLKSEL2_PWM45_S_HXT, 0);
 
    /* Reset PWMB channel0~channel3 */
    SYS_ResetModule(PWM47_RST);
 
    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    //SystemCoreClockUpdate();
    PllClock        = PLL_CLOCK;            // PLL
    SystemCoreClock = PLL_CLOCK / 1;        // HCLK
    CyclesPerUs     = PLL_CLOCK / 1000000;  // For SYS_SysTickDelay()
 
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Set P4 multi-function pins for PWMB Channel2 */
    SYS->P2_MFP = SYS_MFP_P24_PWM4;
 
}
 
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();
 
    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();
 
    /* Lock protected registers */
    SYS_LockReg();
    
    /* Enable PWM Output pin */                        
    PWM_EnableOutput(PWMB, 0x0);
 
    PWM_ConfigOutputChannel(PWMB, PWM_CH0, 1000060);
 
    /* Enable PWM Timer */
    PWM_Start(PWMB, 0x0);
 
    /* Wait until PWMB channel 0 Timer Stop */
    while(PWMB->PDR0 != 0);
 
    /* Disable the PWM Timer */
    PWM_Stop(PWMB, 0x0);
 
    /* Disable PWM Output pin */
    PWM_DisableOutput(PWMB, 0x0);
}
 
 

 

반응형

'스마트홈' 카테고리의 다른 글

[Firmware] M058 - GPIO Interrupt  (0) 2019.05.03
[Firmware] M058 - UART  (0) 2019.05.03
[Firmware] M058 - gpio_timer_delay  (0) 2019.05.03
[Firmware] M058 - gpio_output/input  (0) 2019.05.03
[인공지능] Recurrent Neural Network  (0) 2017.12.04
Comments