Puente H con el PWM mejorado del PIC18F4550

Hola. Quiero utilizar el "PWM mejorado" de un PIC18F4550 y hacer un puente H full bridge.
El micro, según el datasheet lo permite, pero no logro hacerlo funcionar.
Sólo he logrado usar el PWM normal. Utilizo el mikroC y pienso que sea algún valor en algún registro que no estoy teniendo en cuenta

¿Alguien conoce del tema ?
Sin más, gracias.

Código:
unsigned short current_duty, old_duty, current_duty1, old_duty1;
 
void InitMain() {
 
 
PORTA = 255;
TRISA = 255; // configure PORTA pins as input
PORTB = 0; // set PORTB to 0
TRISB = 0; // designate PORTB pins as output
PORTC = 0; // set PORTC to 0
TRISC = 0; // designate PORTC pins as output
PORTD = 0; // set PORTC to 0
TRISD = 0;
PWM1_Init(5000); // Initialize PWM1 module at 5KHz
// CCP1CON = 0b01001100;
// PSTRCON = 0b00011111;
CCP1CON=0b00001100; // Single PWM mode; P1A, P1C active-high; P1B, P1D active-high
//CCPR1L=0; // Start with zero Duty Cycle
 
// ECCP1CON=0b11001111;
// PWM2_Init(5000); // Initialize PWM2 module at 5KHz
}
 
void main() {
InitMain();
current_duty = 16; // initial value for current_duty
// current_duty1 = 16; // initial value for current_duty1
 
PWM1_Start(); // start PWM1
// PWM2_Start(); // start PWM2
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
// PWM2_Set_Duty(current_duty1); // Set current duty for PWM2
 
while (1) { // endless loop
if (RA0_bit) { // button on RA0 pressed
Delay_ms(40);
current_duty++; // increment current_duty
PWM1_Set_Duty(current_duty);
}
 
if (RA1_bit) { // button on RA1 pressed
Delay_ms(40);
current_duty--; // decrement current_duty
PWM1_Set_Duty(current_duty);
}
 
 
 
Delay_ms(5); // slow down change pace a little
}
}
/*
segun google con la siguiente linea debe estar funcionando
pero nada
CCP1CON=0b00001100;
*/
 

Adjuntos

  • 18f4550.zip
    39.4 KB · Visitas: 15
Última edición por un moderador:
Mira bien la hoja de datos en vez de usar google y lo entenderás mejor.

Nada más tienes que configurar lo siguiente:
Los bits 5, 6 y 7 del puerto D, los configuras como salidas. (P1B, P1C y P1D)
Por los bits de salida modulada P1B y P1D, obtendrás las señales PWM.
Configuras T2CON para seleccionar el prescaler, el postescaler y el encendido del Timer2.
PR2 para establecer la frecuencia de operación, CCPR1L (PWM 8 bits) para el ciclo activo.
Y con CCP1CON estableces el tipo de configuración de salida de señal PWM.

Por ejemplo:
CCP1CON = 0b10001100;
Y obtienes modulación por P1B. (RD5)
CCP1CON = 0b01001100;
Y obtienes modulación por P1D. (RD7)
 
Atrás
Arriba