本帖最后由 freebsder 于 2014-8-15 22:34 编辑
图就不上了,驱动某宝上买的,uln2003a+28bjy,有类似设备的朋友可以试试,没设备的看了痒痒不如不看。控制板就lpcxpresso1549 那,sct out引脚用的sct0 的 out0-3, 配置和原理图上的一样,
具体见 app_setup_pin。占空比和频率的调整只需要改变对应的MATCHREL/MATCH即可。
主函数:使能sct,初始化引脚,lpcopen挺方便,就不折腾寄存器了。
- /*
- ===============================================================================
- Name : pwm.c
- Author : $(author)
- Version :
- Copyright : $(copyright)
- Description : main definition
- ===============================================================================
- */
- #if defined (__USE_LPCOPEN)
- #if defined(NO_BOARD_LIB)
- #include "chip.h"
- #else
- #include "board.h"
- #endif
- #endif
- #include <cr_section_macros.h>
- // TODO: insert other include files here
- #include "sct_fsm.h"
- // TODO: insert other definitions and declarations here
- #define SCT_PWM LPC_SCT0 /* Use SCT0 for PWM */
- #define SCT_PWM_RATE 1000000 /* PWM frequency 1MHz */
- /* Setup board specific pin muxing */
- static void app_setup_pin(void)
- {
- /* Enable SWM clock before altering SWM */
- Chip_SWM_EnableFixedPin(SWM_FIXED_SCT0_OUT3);
- Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
- /* Connect SCT output 1 to PIO0_29 */
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT0_O, 6);
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT1_O, 29);
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT2_O, 26);
- Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
- }
- int main(void) {
- #if defined (__USE_LPCOPEN)
- #if !defined(NO_BOARD_LIB)
- // Read clock settings and update SystemCoreClock variable
- SystemCoreClockUpdate();
- // Set up and initialize all required blocks and
- // functions related to the board hardware
- Board_Init();
- // Set the LED to the state of "On"
- Board_LED_Set(0, true);
- #endif
- #endif
- // TODO: insert code here
- Chip_SCTPWM_Init(SCT_PWM);
- Chip_SCTPWM_Stop(SCT_PWM);
- app_setup_pin();
- Chip_SCT_Config(SCT_PWM, SCT_CONFIG_16BIT_COUNTER);
- sct_fsm_init();
- Chip_SCTPWM_Start(SCT_PWM);
- // Force the counter to be placed into memory
- // Enter an infinite loop, just incrementing a counter
- while(1) {
- __WFI();
- }
- return 0 ;
- }
复制代码
四拍
八拍