cencia Inserito: 31 maggio 2007 Segnala Share Inserito: 31 maggio 2007 Ciao a tutti,sarei interessato ad avere una procedura per far funzionare il modulo PWM del mio dsPIC.Qualcuno mi può dare una mano?!!!Finora ho utilizzato la seguenteprocedura ma c'è qualcosa che non va...grazie da subito#include "p30F6010.h"#include "pwm.h"_FOSC(CSW_FSCM_OFF & XT_PLL16);_FWDT(WDT_OFF);_FBORPOR(PBOR_ON & BORV_20 & PWRT_64 & MCLR_EN);#define PWM1H PORTEbits.RE1#define PWM1L PORTEbits.RE0void InitMCPWM(void);int main(void){ LATE = 0x0000; TRISE = 0xFFFF; // Imposta la Porta E PWM1H=1; PWM1L=1; InitMCPWM(); return 0; } // end mainvoid InitMCPWM(void){/* Holds the value to be loaded into dutycycle register */unsigned int period;/* Holds the value to be loaded into special event compare register */unsigned int sptime;/* Holds PWM configuration value */unsigned int config1;/* Holds the value be loaded into PWMCON1 register */unsigned int config2;/* Holds the value to configure the special event triggerpostscale and dutycycle */unsigned int config3;/* The value of ‘dutycyclereg’ determines the duty cycleregister(PDCx) to be written */unsigned int dutycyclereg;unsigned int dutycycle;unsigned char updatedisable;/* Configure pwm interrupt enable/disable and set interruptpriorties */config1 = ( PWM_INT_EN & PWM_INT_PR6& PWM_FLTA_DIS_INT // PWM_FLTA_INT_PR0// PWM_FLTB_DIS_INT// PWM_FLTB_INT_PR0 );ConfigIntMCPWM( config1 );// period This contains the PWM timebase period value to be stored// in PTPER register.period = 511;// sptime This contains the special event compare value to be// stored in SEVTCMP register.sptime = 0x0;// This contains the parameters to be configured in the// PTCON register as defined below:config1 = ( // PWM module enable/disable PWM_EN// PWM_DIS// Idle mode enable/disable& PWM_IDLE_STOP// PWM_IDLE_CON// Output post scaler select& PWM_OP_SCALE1 // interrupt ogni 1 ciclo di PWM// PWM_OP_SCALE2// PWM_OP_SCALE8// PWM_OP_SCALE15// PWM_OP_SCALE16 // interrupt ogni 16 cicli PWM// Input prescaler select// PWM_IPCLK_SCALE1& PWM_IPCLK_SCALE4// PWM_IPCLK_SCALE16// PWM_IPCLK_SCALE64 // PWM mode of operation& PWM_MOD_FREE// PWM_MOD_SING// PWM_MOD_UPDN// PWM_MOD_DBL);// This contains the parameters to be configured in the// PWMCON1 register as defined below:config2 = (// PWM I/O pin pair// PWM_MOD4_COMP// PWM_MOD3_COMP// PWM_MOD2_COMP PWM_MOD1_COMP// PWM_MOD4_IND// PWM_MOD3_IND// PWM_MOD2_IND// PWM_MOD1_IND// PWM H/L I/O enable/disable select//PWM_PEN4H// PWM_PDIS4H// PWM_PEN3H& PWM_PDIS3H// PWM_PEN2H& PWM_PDIS2H& PWM_PEN1H// PWM_PDIS1H// PWM_PEN4L// PWM_PDIS4L// PWM_PEN3L& PWM_PDIS3L// PWM_PEN2L& PWM_PDIS2L& PWM_PEN1L// PWM_PDIS1L//Bit defines related to PWM4 is available only for certain//devices and the suitable data sheet should be referred to.);//This contains the parameters to be configured in the//PWMCON2 register as defined below:config3 = (PWM_SEVOPS1//PWM_SEVOPS2 // PWM_SEVOPS8//PWM_SEVOPS15//PWM_SEVOPS16// Output Override synchronization select& PWM_OSYNC_PWM// PWM_OSYNC_Tcy// PWM update enable/disable// PWM_UDIS& PWM_UEN);OpenMCPWM(period,sptime,config1,config2,config3);/* Configure PWM to generate square wave of 50% duty cycle */dutycyclereg = 1;dutycycle = 512;updatedisable = 0;SetDCMCPWM(dutycyclereg,dutycycle,updatedisable);} Link al commento Condividi su altri siti More sharing options...
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora