Skip to main content
Visitor II
September 11, 2003
Question

problem with timer

  • September 11, 2003
  • 11 replies
  • 1737 views
Posted on September 11, 2003 at 10:31

problem with timer

    This topic has been closed for replies.

    11 replies

    efeixasAuthor
    Visitor II
    August 30, 2003
    Posted on August 30, 2003 at 15:11

    I've tried to do an interrupt every 1ms using the output compare 1 of the timer b without succes.

    I've attached my program but until now it does'nt work because after the first interrupt it re-enter autamaticaly in the interrupt without waiting the time put in timer. Could anyone say me how can i reset the interrupt?

    Thanks

    ________________

    Attachments :

    prova.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0C9&d=%2Fa%2F0X0000000bV7%2F1V_gSoRp9oX1XxYS1uUuR5TpYC9ag6aEcSYMvbcmd5U&asPdf=false
    Visitor II
    September 1, 2003
    Posted on September 01, 2003 at 05:57

    You've forgotten to clear the interrupt flag.

    You must read the OCF1 flag in the Status register.

    Read the datasheet, chapter 'timer' for more details

    Moppie
    efeixasAuthor
    Visitor II
    September 2, 2003
    Posted on September 02, 2003 at 16:56

    Thanks, for your hepl, but it still don't work. I have already the same problem could you see the new program in order to say me if there is anithing wrong?

    Thanks

    Enric Feixas

    ________________

    Attachments :

    prova.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0C4&d=%2Fa%2F0X0000000bV4%2FrIntWekPn3ZIBVLvr5lqRs1._ufHUN_4joN63LxC1A8&asPdf=false
    Visitor II
    September 3, 2003
    Posted on September 03, 2003 at 06:13

    Hi Enric,

    Try this code example.

    It's a ''C'' code but You can convert it in assembler.

    /* Definizione costanti */

    #if(_freqOsc == 16 ) // < 16MHz >

    #define _oneMilli 1000 // costante timer free-running per ottenere il millisecondo

    #define _CC01 0b00001000 // divisore frequenza CPU (OSC/2) per il timer A o B a 1MHz

    #endif

    #if(_freqOsc == 8 ) // < 8MHz >

    #define _oneMilli 1000 // costante timer free-running per ottenere il millisecondo

    #define _CC01 0b00000000 // divisore frequenza CPU (OSC/2) per il timer A o B a 1MHz

    #endif

    /* Variabile WORD di supporto */

    @tiny WORD Delay; // variabile per il ritardo di 1ms usata nell'interrupt timer

    /* Inizializzazione TIMER ''A'' */

    TACR1 = 0x40; /* abilito l'interrupt out Compare su TIMER ''A''*/

    TACR2 = _CC01; /* divisione del clock per il conteggio; Fcpu/x = 1MHz*/

    /* Timer intarrupt handler */

    @interrupt void one_milli(void) /* ROUTINE DI INTERRUPT TIMER ''A'' o ''B'' */

    {

    if(ValBit(TASR,OCF1)) // ogni 1 millisecondo

    {

    Delay =(TAOC1HR<

    Delay += _oneMilli; // somma di nuovo il valore per ottenere il millisecondo

    TAOC1HR=(Delay>>8 ); // questa operazione effettua anche l'ack dell'interrupt

    TAOC1LR=Delay;

    // ...

    // Your code

    //

    }

    else TAOC2LR = 0x00;

    [ Questo Messaggio è stato Modificato da: sixtus il 03-09-2003 09:45 ]
    Visitor II
    September 3, 2003
    Posted on September 03, 2003 at 12:29

    I've attached you're program.

    First load the interrupt registers and then clear teh interrupt flag.

    ________________

    Attachments :

    prova2.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0BR&d=%2Fa%2F0X0000000bV1%2FVAFmZwwer8qvkzciokz4fMWFiJjJebfn7Bq1exR876s&asPdf=false
    efeixasAuthor
    Visitor II
    September 3, 2003
    Posted on September 03, 2003 at 19:23

    Thanks for your help, but it still do'nt work, now I've a different problem, now it's too slowly, it spend 120ms to do the interrupt which I wanted to do in 1ms, could you look in the program what is wrong now?

    Thanks

    Enric Feixas

    ________________

    Attachments :

    prova2.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Bv&d=%2Fa%2F0X0000000bV0%2FijjgziwC6.fMLM88JK1olReJbxslAPgTyzsS_2azUto&asPdf=false
    Visitor II
    September 4, 2003
    Posted on September 04, 2003 at 12:45

    Hello,

    Look inside the attachment.

    Good luck.

    Read carefully the datasheets.

    ________________

    Attachments :

    prova2.asm : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I09V&d=%2Fa%2F0X0000000bV2%2F_JMPJOLCAJb0lcJneoWsnsO8SQClw83mfWNYp6j1PQI&asPdf=false
    efeixasAuthor
    Visitor II
    September 6, 2003
    Posted on September 06, 2003 at 20:55

    Thanks to all of your help, I've solved teh problem! the answer is the program that you can see attached.

    But now I've a new problem because I've started to do another timer with the output compare 2 of timer A, this not and interruption because I only want to put this output in 'ON' at the time I've put in the timer A (different from B). But after putting it in on I want to put it in OFF every time that the interrupt of timer B is activated but I could'nt!

    Could you see in the program what is wrong?

    Thanks

    Enric Feixas

    ________________

    Attachments :

    Demo.asm : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I07f&d=%2Fa%2F0X0000000bV3%2Fg59r0.aMqOkaSOuK40i.3ouGvgeGonP.EN6mSbiDBQI&asPdf=false
    Visitor II
    September 8, 2003
    Posted on September 08, 2003 at 06:13

    Hello,

    Great you solved the last problem.

    You're next problem are in the intterupt vectors

    Timer A and B has different interrupt vectors, so split up the intterupt

    See the attachment

    Succes.

    [ This message was edited by: Moppie on 08-09-2003 09:44 ]

    ________________

    Attachments :

    Demo.asm : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Bp&d=%2Fa%2F0X0000000bUx%2Fp38Aie.dXiP9.F7SRKxFtk06LZzf5K.bFCLHO2RSFvU&asPdf=false
    efeixasAuthor
    Visitor II
    September 8, 2003
    Posted on September 08, 2003 at 18:35

    Thanks for your help, but it still continue with the same problem (after I put the led of output compare 2 in 'ON' I can't put it in 'OFF') , could you say me if there is anything which could be wrong?

    Thanks.

    Enric Feixas