- 首页 > it技术 > >
#include 【dsPIC33F产生PWM】#include "p33fxxxx.h"
#define __33FJ32MC204_H
#define Fcy40000000
#include
_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 RegisterP1DC1 = 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;
}
推荐阅读