PIC12F675 PWM with interrupt

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
Posts: 1
Joined: Tue Feb 14, 2012 3:34 pm

PIC12F675 PWM with interrupt

Post by houseman2004 » Tue Feb 21, 2012 4:03 am

Hi guys,
I tried to programm a Servo control witch works with interrupts. The idea is that Timer0 causes an interrupt. In the interrupt service routine the GP2 Pin is set to 1 and the Timer1 starts. When the Timer1 overflow happens (the high time is over) the GP2 Pin is set to 0 and the Period is over.
The problem is that the programm doesn`t work correctly and i don`t know why. I´m not a very good programmer.
Maybe some of you can analyst the programm and correct them. The Timer values (the times) are not relevant and I will calculate them exactly after the programm will work.
Sorry that I haven`t translatet the comments from German to English.

Here is the programm:

Code: Select all

int Count;     //Zähler für durchläufe

void timer0()
          /*    1-------;  Betrifft nicht Timer0
                -1------;  Betrifft nicht Timer0
                --0-----;  Internet Takt für Timer0 verwenden
                ---0----;  Bei ext. Takt b. stg Flanke inkr. (nicht relevant)
                ----0---;  Prescaler für Timer 0 verwenden
                -----111;  Prescaler   (1:256)
         T0IF_bit=0; //Timer0 Interrupt Flag löschen
         GIE_bit=1;  //Alle unmaskierten interrupts erlauben
         T0IE_bit=1; //Timer0 Interrupt erlauben
         TMR0=180;   // Timer0 Value

 static void interrupt (void)  //ISR
        GP2_bit=1; //Ausgang auf 1
        TMR1H=253; //High Byte berechnen
        TMR1L=232; //Low Byte berechnen

       //Timer1 Konfiguration
         /*    0-------; Nicht relevant
               -0------; Nicht relevant
               --00----; Precsaler (1:1)
               ----0---; Sync. m. ext. Takt (Hier nicht relevant)
               -----0--; Internet Tackt verwenden
               -------1; Timer starten
       while (TMR1IF!=0)  //Warten auf Überlauf
       GP2_bit=0;             //Ausgang auf 0
       TMR1IF_bit=0;          //Timer Flag löschen
       Count++;               //Zähler um 1 erhöhen

void main() 

 while(1) {}


Post Reply