历史上的今天
今天是:2024年11月06日(星期三)
2019年11月06日 | MSP432E401Y-PWM的生成和占空比的调整
2019-11-06 来源:eefocus
* MSP432E4 Empty Project
*
* Description: An empty project that uses DriverLib
*
* MSP432E401Y
* ------------------
* /|| |
* | | |
* --|RST |
* | |
* | PF2 |--->25%PWM
* | PF3 |--->75%PWM
* | |
* | |
* Author:
*******************************************************************************/
/* DriverLib Includes */
#include /* Standard Includes */ #include #include /* Global variable for system clock */ uint32_t getSystemClock; /* PWM ISR */ void PWM0_0_IRQHandler(void) { uint32_t getIntStatus; getIntStatus = MAP_PWMGenIntStatus(PWM0_BASE, PWM_GEN_1, true); MAP_PWMGenIntClear(PWM0_BASE, PWM_GEN_1, getIntStatus); } int main(void) { /* Configure the system clock for 16 MHz internal oscillator */ getSystemClock = MAP_SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_OSC), 16000000); /* The PWM peripheral must be enabled for use. */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))); /* Set the PWM clock to the system clock. */ MAP_PWMClockSet(PWM0_BASE,PWM_SYSCLK_DIV_1); /* Enable the clock to the GPIO Port F for PWM pins */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)); MAP_GPIOPinConfigure(GPIO_PF2_M0PWM2); MAP_GPIOPinConfigure(GPIO_PF3_M0PWM3); MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3)); /* Configure the PWM0 to count up/down without synchronization. */ MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); /* Set the PWM period to 250Hz. To calculate the appropriate parameter * use the following equation: N = (1 / f) * SysClk. Where N is the * function parameter, f is the desired frequency, and SysClk is the * system clock frequency. * In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles. Note that * the maximum period you can set is 2^16 - 1. */ MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 64000); /* Set PWM0 PF0 to a duty cycle of 25%. You set the duty cycle as a * function of the period. Since the period was set above, you can use the * PWMGenPeriodGet() function. For this example the PWM will be high for * 25% of the time or 16000 clock cycles (64000 / 4). */ MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 4); /* Set PWM0 PF1 to a duty cycle of 75%. You set the duty cycle as a * function of the period. Since the period was set above, you can use the * PWMGenPeriodGet() function. For this example the PWM will be high for * 7% of the time or 16000 clock cycles 3*(64000 / 4). */ MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 4); MAP_IntMasterEnable(); /* This timer is in up-down mode. Interrupts will occur when the * counter for this PWM counts to the load value (64000), when the * counter counts up to 64000/4 (PWM A Up), counts down to 64000/4 * (PWM A Down), and counts to 0. */ MAP_PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_1, PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD | PWM_INT_CNT_AU | PWM_INT_CNT_AD); MAP_IntEnable(INT_PWM0_1); MAP_PWMIntEnable(PWM0_BASE, PWM_INT_GEN_1); /* Enable the PWM0 Bit 0 (PF0) and Bit 1 (PF1) output signals. */ MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true); /* Enables the counter for a PWM generator block. */ MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_1); /* Loop forever while the PWM signals are generated. */ while(1) { } }
上一篇:MSP432时钟系统CS
史海拾趣
|
我现在想用单片机来控制 3个220V电动机 或是 5个电动机 而一般的电路设计是 光偶 加 可控硅 实现关与开 或是继电器实现 但是电动机开与关 到底有没有执行单片机没有得到 ...… 查看全部问答> |
|
我用万用表可以测到晶振的起振电压,接上示波器,测不到电压和频率,请教各位大哥这个是不是示波器探针电容的影响? 示波器的设置:探针 为 *10 挡,交直流都试过了 … 查看全部问答> |
|
SEGA MD是很久以前的TV游戏机, 前些时候整理了一下, 找到完整的开发包: 1)C,汇编开发工具和库; 2)调试工具(免ICE开发); 3)MIDI音乐转换工具; 工具虽老了些,但当初用这个工具开发过很多的商业SEGA游戏, 包括为日本著名游戏厂家BANDAI开发的SEGA ...… 查看全部问答> |
|
按国内医学会制定的心电图标准,心电信息数字化精度不小于12bit,(信号输入范围+/-5mV的情况下,心电信号最小分辨率2.44uV)心电采样率不低于500Hz 我们想做一款心电图的分析软件,想找一个可靠心电电路,当然比上面标准更高的更好 最好有实际使用过 ...… 查看全部问答> |
|
求教用SYSTEMVIEW做PN码相应同步系统. 1、判决器用哪个控件? 2、VCO所连接的时钟用什么控制? 最好能有解决电路图。谢谢~~… 查看全部问答> |




