Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Oh, you get the correct result, but not the wanted result
You want the waveform to be inverted, but not the duty cycle to be complemented.
You cannot use this: PORTB = ~CCP1 because the result on PORTB is parallel. The easiest way is to use a hardware inverter at the output of CCP1.
Or, is the program running anything else? If not then you can update the duty cycle of CCP1 in the timer 2 ISR. In the main, poll RC2 (CCP1) and invert this pin to any output pin. Or anyone has better solution?
I just looked at the chip your using, check the function of bit 6&7 of CCP1CON. In fact, I think you can set the chip up so that CCP1 output is inverted - see page 147 of the data sheet.
Mike.
Hi Pommie,
Another thing, can PIC do deadtime timing delay?
I just looked at the chip your using, check the function of bit 6&7 of CCP1CON. In fact, I think you can set the chip up so that CCP1 output is inverted - see page 147 of the data sheet.
Mike.
#include <P18F4520.h>
#include <timers.h>
#pragma interrupt interrupt_1
void interrupt_1 (void);
void main(void)
{
OpenTimer0( TIMER_INT_OFF & T0_8BIT & T0_SOURCE_INT & T0_PS_1_256 );
if (INTCONbits.TMR0IF=1)
interrupt_1();
}
void interrupt_1(void)
{
// Interrupt Code - For example like reading analog input
}
#include <P18F4520.h>
#include <timers.h>
#pragma interrupt interrupt_1
void interrupt_1 (void);
void main(void)
{
OpenTimer0( TIMER_INT_OFF & T0_8BIT & T0_SOURCE_INT & T0_PS_1_256 );
if (INTCONbits.TMR0IF=1)
interrupt_1();
}
void interrupt_1(void)
{
INTCONbits.TMR0IF = 0;
// Interrupt Code - For example like reading analog input
}
If you have a look at this thread, about a dozen posts down I posted some code showing how to setup the interrupt vector and routine. From this you should be able to work out how to do your interrupt.
BTW, a 1μS interrupt is very fast. Are you sure you don't mean 1mS?
Mike.