bobo8080
Nouveau
salut tt le monde ; est ce que qq1 peu m'aider à configurer le POWER CONTROL PWM MODULE car je trouvre rien sur le net;
ce que je veux fair :
-utiliser le l'osc interne pour avoir 8MHz et lir la frequ/4 sur le pin RA7.
-utiliser les 8 sortie pwm du pic
-les sortie pwm en mode complementaire
-avoir une frequencce min de 453KHz pour pwm
-savoir regeler le duty cyle de chaque paire pwm
merci d'avance.
voici mon code source si vous pouvez m'informer s'il ya des erreurs.
----------------------------------------------
----------------------------------------------
#include <p18f4431.h>
#include <pwm.h>
//-------------------------------Configuration setting ----------------------------------------------
/**
* Oscillator is configured as HS
* Fail safe monitor is enabled
* watch dog timer is disabled
* Extended instruction mode is disabled
* oscillator switch over is enabled
*/
#pragma config OSC = IRC //Internal RC, RA6 is CLKOUT, RA7 is I/O,
#pragma config MCLRE = OFF //désactiver la pin de Reset
#pragma config LVP = OFF //Low Voltage Programming désactivé
#pragma config DEBUG = OFF //débug désactivé
#pragma config FCMEN = OFF //Fail-Safe Clock désactivée
#pragma config PWRTEN = OFF //Power-up Timer désactivé
#pragma config BOREN = OFF //Reset dû a une tension trop basse désactivé
#pragma config BORV = 20 //Brown-out Reset Voltage
#pragma config WDTEN = OFF //Watchdog désactivé
#pragma config WDPS = 1024 //prédiviseur du watchdog
#pragma config STVREN = OFF //pas de reset du à la pile
#pragma config IESO = ON
/*********************************************************************
Function: void setup_io(void)
Overview: Sets up io ports for in and out in stepper mode
********************************************************************/
void setup_io(void)
{
TRISAbits.TRISA7 = 1; // INPUTS dir1
ANSEL0bits.ANS0 = 1; // SET RA0 AS ANALOG INPUT
TRISAbits.TRISA6 = 1; // INPUTS step1
ANSEL0bits.ANS1 = 1; // SET RA1 AS ANALOG INPUT
TRISBbits.TRISB5 = 0; // PWM4 (L1 MOTOR1 HBRIDGE)
TRISBbits.TRISB4 = 0; // PWM5
TRISBbits.TRISB2 = 0; // PWM2 (L2 MOTOR1 HBRIDGE)
TRISBbits.TRISB3 = 0; // PWM3
TRISBbits.TRISB0 = 0; // PWM0 (L1 MOTOR2 HBRIDGE)
TRISBbits.TRISB1 = 0; // PWM1
TRISDbits.TRISD6 = 0; // PWM6 (L2 MOTOR2 HBRIDGE)
TRISDbits.TRISD7 = 0; // PWM7
// define i/o bits
// PORT A
#define CUR_L1_M1 RA0 //IN FOR CURRENT LIMIT (L1 MOTOR1)
#define CUR_L2_M1 RA1 //IN FOR CURRENT LIMIT (L2 MOTOR1)
// PORT B
#define DIR1 RB7 //RB7 dir1 (Input)
#define STEP1 RB6 //RB1 step2 (Input)
}
/*********************************************************************
Function: void setup_pwm(void)
Overview: Sets up pwm modul
********************************************************************/
void setup_pwm(void)
{
//configuration du pwm :
PTCON0 = 0; //1:1 prescale,1:1 postscale
PWMCON0 = 0x70; //All odd PWM I/O pins enabled for PWM output
//PWM Output Pair in Complementary mode
PWMCON1 = 1; // 1:1 Postscale
PTPERL = 3; // frequence du pwm
PTPERH = 0;
DTCON = 0; // ++++pas de temps mort
PTCON1bits.PTEN = 1; // demarrage du module pwm
//??---------------------------------------------------
FLTCONFIG = 0; // pas de gestion des défauts
//---------------------------------------------------
//??DEFINITION du duty cycle :
PDC0H = 0X31; //SET Duty Cycle
PDC0L = 0X00;
//---------------------------------------------------
OVDCOND = 0XFF; //ACTIVATION DES SORTIES PWM
}
/********************************************************************
*********************************************************************/
void main(void)
{
setup_io();
setup_pwm();
while(1 == 1);
}
ce que je veux fair :
-utiliser le l'osc interne pour avoir 8MHz et lir la frequ/4 sur le pin RA7.
-utiliser les 8 sortie pwm du pic
-les sortie pwm en mode complementaire
-avoir une frequencce min de 453KHz pour pwm
-savoir regeler le duty cyle de chaque paire pwm
merci d'avance.
voici mon code source si vous pouvez m'informer s'il ya des erreurs.
----------------------------------------------
----------------------------------------------
#include <p18f4431.h>
#include <pwm.h>
//-------------------------------Configuration setting ----------------------------------------------
/**
* Oscillator is configured as HS
* Fail safe monitor is enabled
* watch dog timer is disabled
* Extended instruction mode is disabled
* oscillator switch over is enabled
*/
#pragma config OSC = IRC //Internal RC, RA6 is CLKOUT, RA7 is I/O,
#pragma config MCLRE = OFF //désactiver la pin de Reset
#pragma config LVP = OFF //Low Voltage Programming désactivé
#pragma config DEBUG = OFF //débug désactivé
#pragma config FCMEN = OFF //Fail-Safe Clock désactivée
#pragma config PWRTEN = OFF //Power-up Timer désactivé
#pragma config BOREN = OFF //Reset dû a une tension trop basse désactivé
#pragma config BORV = 20 //Brown-out Reset Voltage
#pragma config WDTEN = OFF //Watchdog désactivé
#pragma config WDPS = 1024 //prédiviseur du watchdog
#pragma config STVREN = OFF //pas de reset du à la pile
#pragma config IESO = ON
/*********************************************************************
Function: void setup_io(void)
Overview: Sets up io ports for in and out in stepper mode
********************************************************************/
void setup_io(void)
{
TRISAbits.TRISA7 = 1; // INPUTS dir1
ANSEL0bits.ANS0 = 1; // SET RA0 AS ANALOG INPUT
TRISAbits.TRISA6 = 1; // INPUTS step1
ANSEL0bits.ANS1 = 1; // SET RA1 AS ANALOG INPUT
TRISBbits.TRISB5 = 0; // PWM4 (L1 MOTOR1 HBRIDGE)
TRISBbits.TRISB4 = 0; // PWM5
TRISBbits.TRISB2 = 0; // PWM2 (L2 MOTOR1 HBRIDGE)
TRISBbits.TRISB3 = 0; // PWM3
TRISBbits.TRISB0 = 0; // PWM0 (L1 MOTOR2 HBRIDGE)
TRISBbits.TRISB1 = 0; // PWM1
TRISDbits.TRISD6 = 0; // PWM6 (L2 MOTOR2 HBRIDGE)
TRISDbits.TRISD7 = 0; // PWM7
// define i/o bits
// PORT A
#define CUR_L1_M1 RA0 //IN FOR CURRENT LIMIT (L1 MOTOR1)
#define CUR_L2_M1 RA1 //IN FOR CURRENT LIMIT (L2 MOTOR1)
// PORT B
#define DIR1 RB7 //RB7 dir1 (Input)
#define STEP1 RB6 //RB1 step2 (Input)
}
/*********************************************************************
Function: void setup_pwm(void)
Overview: Sets up pwm modul
********************************************************************/
void setup_pwm(void)
{
//configuration du pwm :
PTCON0 = 0; //1:1 prescale,1:1 postscale
PWMCON0 = 0x70; //All odd PWM I/O pins enabled for PWM output
//PWM Output Pair in Complementary mode
PWMCON1 = 1; // 1:1 Postscale
PTPERL = 3; // frequence du pwm
PTPERH = 0;
DTCON = 0; // ++++pas de temps mort
PTCON1bits.PTEN = 1; // demarrage du module pwm
//??---------------------------------------------------
FLTCONFIG = 0; // pas de gestion des défauts
//---------------------------------------------------
//??DEFINITION du duty cycle :
PDC0H = 0X31; //SET Duty Cycle
PDC0L = 0X00;
//---------------------------------------------------
OVDCOND = 0XFF; //ACTIVATION DES SORTIES PWM
}
/********************************************************************
*********************************************************************/
void main(void)
{
setup_io();
setup_pwm();
while(1 == 1);
}