Delay routine

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
JoSi_3317786
Level 2
Level 2
First like received First like given

Hey, guys, I need some help with my program. I using Timer component to generate a 5 seconds delay while execute somethings. Using a clock@10kHz the period should be 50000 to give me 5 seconds, but when I set Timer_WritePeriod(50000) the count never hits zero to generate a pulse at TC.

When I set Timer_WritePeriod(20) the TC occur, but I dont know how accurate the delay is.

Is there something wrong?

void Tempo(void)//5 seconds

    { 

       Control_Reg_Timer_Write(0);//Enable Timer

        Timer_Stop();//Stop timer

        //Timer_ClearFIFO();

        Timer_WriteCounter(0);//

        Timer_WritePeriod(20);//

        Timer_Enable()  ;//Enable Timer

        while(Status_Reg_Read() == 0)//wait for the TC rising edge

            {

            UART_PC();

            LED_Write(1);

            }

        Control_Reg_Timer_Write(1);//Reset Timer

        LED_Write(0);

        return;

    }

Sem título.png

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Reading the question and answers again, I noticed that you could connect "Interrupt" component to the "tc" pin, too.

With this you can catch the rising edge of "tc" without much hassle.

IMHO, using "interrupt" seems more "formal", though.

schematic

001-schematic.JPG

Note: main.c is the same with my previous post

Tera Term log

000-TeraTerm-log.JPG

moto

View solution in original post

5 Replies
This widget could not be displayed.