The PIC I'm playing with is a 18F2550 and I'm using Timer0 in order to move three servo motors in different directions simultaneously. The prescaler, the ports, and the interrupt bits are well set as far as I can consider, however, when I simulate the program on Proteus I only get one of the three square waves with the "perfect" duty cycle.
In the example below, the variables I use are set so the three square waves can have the same duty cycle, therefore, they should have the same shape on the oscilloscope, but unfortunately no, the first two appear as if they switched off right after switching on for some reason. Appreciating beforehand any kind of help or comments.
Code: Select all
/******************************Variable Designation****************************/
char counter=0;
char posone, postwo, posthree;
/********************************Interrupt Routine*****************************/
void interrupt()
{
if (INTCON.TMR0IF==1)
{
INTCON.TMR0IF=0;
counter++;
/**********************Three PWMs Start Here Simultaneously*******************/
if (counter==39)
{
PORTA.RA0=1;
PORTA.RA1=1;
PORTA.RA2=1;
counter=0;
}
if(counter==posone)
PORTA.RA0=0;
if(counter==postwo)
PORTA.RA1=0;
if(counter==posthree)
PORTA.RA2=0;
}
}
/**********************************Main Routine********************************/
void main() {
INTCON.GIE=1;
INTCON.TMR0IE=1;
TRISA.RA0=0;
TRISA.RA1=0;
TRISA.RA2=0;
PORTA.RA0=0;
PORTA.RA1=0;
PORTA.RA2=0;
T0CON.T0CS=0;
T0CON.PSA=0;
T0CON.T0PS2=0;
T0CON.T0PS1=0;
T0CON.T0PS0=0;
while(1)
{
posone=20;
postwo=20;
posthree=20;
}
}