打印
[MCU]

MSP432评测9-----PWM

[复制链接]
811|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 Cjy_JDxy 于 2020-4-19 12:06 编辑

今天搞了一下PWM。
PWM腿为P2.4

代码:
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

uint8_t TXData = 1;
uint8_t RXData = 0;

//![Simple Timer_A Config]
/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig =
{
        TIMER_A_CLOCKSOURCE_SMCLK,
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
        32000,
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        TIMER_A_OUTPUTMODE_RESET_SET,
        3200
};
//![Simple Timer_A Config]

int main(void)
{
     /* Halting the watchdog */
    MAP_WDT_A_holdTimer();

    //![Simple Timer_A Example]
    /* Setting MCLK to REFO at 128Khz for LF mode
     * Setting SMCLK to 64Khz */
    MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
    MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
    MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P6.7 for button
     * interrupt */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
            GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
    MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);

    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
    //![Simple Timer_A Example]

    /* Enabling interrupts and starting the watchdog timer */
    MAP_Interrupt_enableInterrupt(INT_PORT1);
    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableMaster();

    /* Sleeping when not in use */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}

/* Port1 ISR - This ISR will progressively step up the duty cycle of the PWM
* on a button press
*/
void PORT1_IRQHandler(void)
{
    uint32_t status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);

    if (status & GPIO_PIN1)
    {
        if(pwmConfig.dutyCycle == 28800)
            pwmConfig.dutyCycle = 3200;
        else
            pwmConfig.dutyCycle += 3200;

        MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
    }
}

效果图:

工程:
PWM.rar (1.87 MB)

使用特权

评论回复

相关帖子

沙发
zhangmangui| | 2020-4-19 21:19 | 只看该作者
工具很全  工作室还是学校

使用特权

评论回复
板凳
Cjy_JDxy|  楼主 | 2020-4-20 07:53 | 只看该作者
zhangmangui 发表于 2020-4-19 21:19
工具很全  工作室还是学校

公司。

使用特权

评论回复
地板
21ic小喇叭| | 2020-4-20 14:52 | 只看该作者
感谢分享,周末还愿意写评测,太佩服了!

使用特权

评论回复
5
zhangmangui| | 2020-4-21 21:45 | 只看该作者
21ic小喇叭 发表于 2020-4-20 14:52
感谢分享,周末还愿意写评测,太佩服了!

我们没有周末 妹子

使用特权

评论回复
6
八层楼| | 2020-5-9 16:18 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
7
观海| | 2020-5-9 16:19 | 只看该作者
至今还未用过pwm啊

使用特权

评论回复
8
guanjiaer| | 2020-5-9 16:26 | 只看该作者
楼主公司是硬件研发的吗

使用特权

评论回复
9
heimaojingzhang| | 2020-5-9 16:26 | 只看该作者
在中断里处理  会不会有影响

使用特权

评论回复
10
keaibukelian| | 2020-5-9 16:27 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
11
Cjy_JDxy|  楼主 | 2020-5-9 16:27 | 只看该作者
guanjiaer 发表于 2020-5-9 16:26
楼主公司是硬件研发的吗

开发试验机,包括硬件和软件。

使用特权

评论回复
12
Cjy_JDxy|  楼主 | 2020-5-9 16:28 | 只看该作者
heimaojingzhang 发表于 2020-5-9 16:26
在中断里处理  会不会有影响

不会。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:绿水本无忧因风皱面,青山原不老为雪白头。

553

主题

3520

帖子

19

粉丝