Dale Gregg
Junior Member level 3
- Joined
- Jul 23, 2013
- Messages
- 29
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 3
- Location
- Leeds, United Kingdom
- Activity points
- 263
Hi,
I was hoping someone might be able to help me. My problem is with a SPWM controller using a PIC. The PWM signal outputs from CCP1 (A0 on the logic analyser LA), that's working fine. The logic circuit, the two AND and NOT gates are also working as they should (A1 and A2 on LA, A2 been the inverse of A1).
RD0 is coded to change state every half cycle, thats after the last PWM duty cycle in the sequence, the counter for this is "a" and "div" is the number of duty cycles (39).
A1/A2 should change state every half cycle (when the pulses on A0 get small) but instead A1 stays Hi for a while dips low for a much shorter time then comes back up, fairly regular but completely out of sync(they should be hi and low equal amounts of time). The next pics zoomed out,
This is the interrupt section of the code where the output toggles,
void interrupt() //Interrupt Function
{
/*
*/
if(TMR2IF_bit==1) //At PWM period end
{
if(a>=di) //when counter reaches end of string
{
if(RD0_bit==1) //Toggle H bridge switches
{
RD0_bit = 0;
}
else
{
RD0_bit = 1;
}
a=0; //reset counter
}
else
{
dctrans=a; //converts int to char
CCPR1L = sinedc[dctrans]; //Loads values from sine char string
//to DC
a++; //increment counter
TMR2IF_bit = 0; //TMR2IF reset
}
}
}
I can't find any fault in the code, I've used the debugger step by step and found nothing out of place. Could it be because the toggle code is in the interrupt?
Regards,
Dale
I was hoping someone might be able to help me. My problem is with a SPWM controller using a PIC. The PWM signal outputs from CCP1 (A0 on the logic analyser LA), that's working fine. The logic circuit, the two AND and NOT gates are also working as they should (A1 and A2 on LA, A2 been the inverse of A1).
RD0 is coded to change state every half cycle, thats after the last PWM duty cycle in the sequence, the counter for this is "a" and "div" is the number of duty cycles (39).
A1/A2 should change state every half cycle (when the pulses on A0 get small) but instead A1 stays Hi for a while dips low for a much shorter time then comes back up, fairly regular but completely out of sync(they should be hi and low equal amounts of time). The next pics zoomed out,
This is the interrupt section of the code where the output toggles,
void interrupt() //Interrupt Function
{
/*
*/
if(TMR2IF_bit==1) //At PWM period end
{
if(a>=di) //when counter reaches end of string
{
if(RD0_bit==1) //Toggle H bridge switches
{
RD0_bit = 0;
}
else
{
RD0_bit = 1;
}
a=0; //reset counter
}
else
{
dctrans=a; //converts int to char
CCPR1L = sinedc[dctrans]; //Loads values from sine char string
//to DC
a++; //increment counter
TMR2IF_bit = 0; //TMR2IF reset
}
}
}
I can't find any fault in the code, I've used the debugger step by step and found nothing out of place. Could it be because the toggle code is in the interrupt?
Regards,
Dale