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
So, I thought I'd finished this part of the project and was just tidying up when the above PWM output starting happening. The PWM signal is a half sine wave and was working fine but now has a pulse for about 2 periods at the start/finish of each cycle. This therefore messes up my output sine. I've spent most of the day looking at it, I've stripped the code back to the bare minimum played around with char string lengths, order of the code and its still there! Could this just be an issue with Proteus?
Code:
unsigned char sinedc[39]={ 0, 20, 60, 79, 98, 116, 134, 150, 166, 180,
194, 206, 217, 226, 234, 240, 245, 248, 250, 250,
248, 245, 240, 234, 226, 217, 206, 194, 180, 166,
150, 134, 116, 98, 79, 60, 40, 20, 0
};
unsigned char a; //Loop counter
unsigned char di; //Number of divisions
void interrupt() //Interrupt Function
{
if(TMR2IF_bit==1) //At PWM period end
{
if(a>=di) //when counter reaches end of string
{
a=0; //reset counter
}
else
{
CCPR1L = sinedc[a]; //Loads values from sine char string
//to DC
a++; //increment counter
}
TMR2IF_bit = 0; //TMR2IF reset
}
}
void main() {
/*DC Loading*/
a=0;
di=38;
}
I've tried removing the else statement and putting the code from there above the if statement, this for some reason loses the first 3 or 4 pulses from the beginning and end of the signal. di limits the count to 38 as there are 39 values hence 0-38.
Anyone any ideas?