什么是FPWM

什么是FPWM,第1张

FPWM(强制的脉宽调制)是一种恒流输出为基础的控制方式,它的工作原理是无论输出负载如何变化总是以一种固定频率工作,高侧FET在一个时钟周期打开,使电流流过电感,电感电流上升产生通过感抗的电压降,这个压降通过电流感应放大器放大,来自电流感应放大器的电压被加到PWM比较器输入端,和误差放大器的控制端作比较,一旦电流感应信号达到这个控制电压,PWM比较器就会重新启动关闭高侧FET开关的逻辑驱动电路,低侧的FET会在延迟一段时间后打开。

PWM就是脉冲宽度调制的英文缩写,方波高电平时间跟周期的比例叫占空比,例如1秒高电平1秒低电平的PWM波占空比是50%,意思就是这个控制器输出的脉冲宽度是可以调节的

或者说在开关电源中,输出电压的调节功能是通过脉冲宽度调制的原理实现的,所以PWM不能直接说是调节输出电压,只是通过PWM功能间接实现了调压的功能。

定时/计数器是提供定时计数用,它是独立开来的,也就是说当定时/计数器工作的时候不会影响单片机的PC资源。这就是他的优点,你用软件的话是可以定时/计数,但是它是用每条指令的机器周期,让PC一直执行这些个指令,不能去做别的事情得到的延时,明显 浪费了PC资源。

#include <intrins.h>

#include <stdio.h>

#include <math.h>

#include "UPSD3200.H"

#include "upsd_pwm.h"

#define uint unsigned int

#define uchar unsigned char

PSD_REGS PSD8xx_reg _at_ csiop

#define KEYIO (~(PSD8xx_reg.DATAIN_A)) &0x07

sbit CP=P4^7

sbit U_D=P1^1

void init_system()// 系统初始化

uchar keyboard()

void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth)

uchar Adjust_station=NO

unsigned char data x,flag

unsigned char keyboard() //键盘输入

{

unsigned char a=0xff,b=0x01,c=0xf8,d//有按键的位置

uint i

do{

a=KEYIO|c

}while(a==0xff)

if (a == 0xfe){d = '1'}

else if (a == 0xfd){d = '2'}

else if (a == 0xfb){d = '3'}

else {d = '0'}

return(d)

}

void uPSD_PWM4_Init(void)

unsigned int PWM_prescaler

P4SFS |= 0x80

PWM_prescaler = (unsigned int)((FREQ_OSC/2)/PWM4_INPUT_freq)//PWM4输入脉冲频率 K

PSCL1L = PWM_prescaler &0x00ff

PSCL1H = (PWM_prescaler >>8)

}

void StepMotor_GO(bit direction,uint speed) {

unsigned char PWM_Period, PWM_PulseWidth

uint temp_uint

U_D = direction//方向

temp_uint = (PWM4_INPUT_freq*1000)/speed

PWM_Period = (unsigned char)temp_uint

PWM_PulseWidth = PWM_Period/2

uPSD_PWM4_Variable(PWM_Period,PWM_PulseWidth)

}

void StepMotor_STOP(void)

{

P4SFS &= 0x7f

}

void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth)

{

P4SFS |= 0x80

PWMVP = PWM_Period

PWMVPW = PWM_PulseWidth

PWMCON |= 0x20

}

void initkey(void){

PSD8xx_reg.DATAOUT_A=0xFF

PSD8xx_reg.CONTROL_A=0x00

PSD8xx_reg.DIRECTION_A=0x00

}

void init_system() // 系统初始化

{

WDKEY=0x55

P4SFS = (unsigned char) (0x08 <<3)

uPSD_PWM_Channel_8bit(3,243)

问题补充:(接着上面的序)

void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned int PWM_freq8, unsigned char PWMCON_value)

{

unsigned int PWM_prescaler

unsigned char output_polarity_mode

output_polarity_mode = PWMCON_value &0x8F

PWMCON = (PWMCON &0x70) | output_polarity_mode

P4SFS = (unsigned char) (0x08 <<PWM_channel_no)

PWM_prescaler = (unsigned int) ( (((unsigned int) FREQ_OSC) / 2) / PWM_freq8)

PSCL0L = PWM_prescaler &0x00ff

PSCL0H = (PWM_prescaler >>8)

PSCL1L = PWM_prescaler &0x00ff

PSCL1H = (PWM_prescaler >>8)

}

void uPSD_PWM_Disable(void)

{

PWMCON &= 0xDF

}

void main(void){

x=0

init_system()

flag=1

while(flag==1){

x=keyboard()

if(x=='1') {StepMotor_GO(0,100)}

else if(x=='2') {StepMotor_GO(1,500)}

else if(x=='3') { StepMotor_STOP()uPSD_PWM_Disable()}

else if(x=='0') {uPSD_PWM_Disable()}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11425731.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存