Reset a timer in one shot mode

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello

   

I have a one shot timer that I want to start multiple times on my demands in software. I have the following setup

   

For TopDesign see attach picture.

   

The isr code:

   

 Timer_1_ReadStatusRegister();
/* Set the flag variable */
toggle_flag = 1;

   

the main code:

   

CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */

isr_1_Start();
Timer_1_Start();

for(;;)
{
if(toggle_flag == 1)
{
toggle_flag = 0;
Timer_1_Start();
}
}

   

But it will only goes into the isr once (because it is a one shot timer). How do I get it to go into the isr multiple time? what did I do wrong?

   

An other thing in the datasheet for the timer it state the following but it does make complete sence to me can anyone explain?

   

   

"Note In order to be sure that One Shot mode does not start prematurely, you should use a

   

Trigger Mode to control the start time, or use some form of software enable mode (Software

   

Only or Software and Hardware)."

   

Martin 

0 Likes
9 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Timer_Start() will not reset the timer! You'll need to use the reset terminal (I used additionally a control-register and toggled a bit).

   

Keep in mind that the reset is NOT asynchronus, so you'll need an additional FF to sync with the input-clock.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thx you.

   

Before I posted this thread I did try to use a control reg with an asynchronous reset that didt work, but that didt work. I will tried you suggestion soon.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When you have any troubles with your project it is much easier for us to have a look at when you upload the complete project here.

   

To do so:in Developer 5.2:  Build -> Clean Project

   

then Zip (NOT Raw!) the complete folder and upload it here.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi mtraedholm,

   

 

   

You can also try using the "Trigger Mode" as Rising edge or falling edge to trigger a shot.

   

After the trigger, the component will require a reset.

   

Look at the schematic below:

   

 

   

 

   

 

   

You can use the Terminal Count output of the Timer and OR it with "Low" to trigger a reset after every trigger ends. Hence, your next trigger will respond again. This will eliminate the requirement of manually resetting the Timer everytime.

   

To trigger, you can make a control register drive high and low (for rising or falling edge trigger). In this case, there is no necessity to use interrupt terminal, hence "Interrupt on TC" should be disabled.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
    Dasq, your solution will work only for higher clock frequencies. When you set the clock to 1kHz the one-shot will not trigger.   
   
    There are two solutions: enlarge the trigger-pulse with DFF or use for the control-register "Pulse Mode" (which is not for all silicon versions available).   
   
        
   
    See attached project.   
   
        
   
    Bob   
0 Likes
Anonymous
Not applicable

Hi Bob,

   

 

   

Thanks for the suggestion.

   

My bad, I tested the project by using large delays (in order of ms) and it didn't mis-trigger.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

Sorry to reply in old thread, but whenever we search for reset one shot timer this thread appears.

   

As Bob suggested we have control register to toggle Reset input as in project.

   

1. We have downloaded timer example which was UDB.

   

2. We changed to 16 bit fixed function.

   

3. Run mode One shot

   

4. We have used a Control reg to control Reset of timer, this control register is in "Pulse mode".

   

5. We have also used TC output to make Reset High

   

6. Reset is brought down to Low in software via setting the Contorl Register whenever you need to start again the One shot.

   

7. We tested it with 1KHz, 100KHz, 1MHz and 24MHz bus clock.

   

We used this to avoid UDB. Please comment about this approch if we are mistaken somewher.

   

Thanks in advance.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I would recommend changing this -

   

 

   

uint8 InterruptCnt;

uint8 Flag_If_Int=0;

   

 

   

to this -

   

 

   

uint8 volatile InterruptCnt;


uint8 volatile Flag_If_Int=0;

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Hi Dana,

   

Thanks for the valuable inputs. Yes I will correct that, please also comment on the .cysch and the method I adopted for resetting One shot timer.

0 Likes