dsPIC33F产生PWM

#include <p33fJ32MC204.h>
#include "p33fxxxx.h"
#define __33FJ32MC204_H
#define Fcy  40000000
#include <delay.h>
_FOSCSEL(FNOSC_FRCPLL);

void delay_ms(long ms)
{
__delay32(ms*(Delay_1mS_Cnt));//mirar en delay.h
}

void inicializarPWM()
{
	P1TCON = 0;
	P1TMR = 0;
	P1TPER = 999; //(FCY/FPWM -1 ) ; // Compute Period based on CPU speed
	P1SECMP = 0; 

	 PWM1CON1 = 0x0E11; // Enable PWM output pins and configure them as complementary mode   
	 PWM1CON2 = 0x0000;    
	 P1DTCON1 = 0x0000;
	 P1DTCON2 = 0x0000; 
	 P1FLTACON = 0x0000;//PxFLTACON: Fault A Control Register
	 
	 P1DC1 = 1000; //bit 15-0 PxDC1<15:0>: PWM Duty Cycle 1 Value bits
	 
	 //LA BUENA
	 P1OVDCON=0Xff00; 
	 P1TCONbits.PTEN = 1;  
	
	TRISBbits.TRISB8 = 0;
}

int main(void)
{
	/* Configure Oscillator to operate the device at 40Mhz */ 
	// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 
	// Fosc= 7.37M*43(2*2)=80Mhz for 7.37M input clock 
	PLLFBD=41;     // M=43 
	CLKDIVbits.PLLPOST=0;  // N1=2 
	CLKDIVbits.PLLPRE=0;  // N2=2 

	
    inicializarPWM();

	
	 while(1)
	{
	PORTB=~PORTB;
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值