Timer3.start(100) takes 100uS to initialize, why?

hi I want to start timer inside a another ISR. I wrote tihs code;

here is the setup:

  Timer3.attachInterrupt(ad_send);
  Timer3.start(200);
  Timer4.attachInterrupt(timer4Interrupt);

and here is tha ad_send function

void ad_send(){
  digitalWrite(tx_pin,1);
  digitalWrite(8,1);
  boolean y=bitRead(i,0);
 if(y){Timer4.start(100);}

  else{Timer4.start(50); }
  
   i++;
   digitalWrite(8,0);
}

here is

void timer4Interrupt(){
  Timer4.stop();
  digitalWrite(tx_pin,0);}

what is want is make transmit pin (tx_pin) rising (make low to high) at every 200uS, that why I use timer3.start(200); and after rising I start timer 4 and pull down tx_pin to low , pull down period depends on address bit,

but I checked the pin 8 using oscilloscope, you can see I pull up pin 8 at begin of timer 3 ISR (ad_send) & pull down when exists. but it takes exactly 100uS or 50uS.

why Timer4.start takes that much time? so my code not function correctly? are there any other way to do this?

how to initialize timer quickly inside a ISR?

After 13 posts, you should know better:-

You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

It’s still not too late to edit your post and do this. You’ll make potential helpers much happier. :slight_smile:

Edit: And maybe you should have made the font of that code a bit smaller - I could almost read it.

Thanks Steve, I edited my post, That way is really nice. So any help regarding the problem?

I want to initialize timer inside a ISR, that ISR may be timer interrupt routing or external interrupt routing.

But initialization do not take much time? in my code it takes 100uS when Timer4.start(100) is used, if I comment it, it takes only 8uS.

even I tried with Timer2, same results, I am using arduino Due, DueTimer.h is my library in use.

Can I use serial port to sample incoming signal? I do not need serial.read, because it takes time to read, instead on my own protocol , will serial port hardware make my lifes easy?

frechi91: Thanks Steve, I edited my post, That way is really nice. So any help regarding the problem?

Sorry, my experience with timers and interrupts in AVR chips is very limited, and I don't use a Due, so I won't try to hazard a guess. I'll leave that to someone with experience in those areas.

But since it looks like you're trying to 'cook' your own serial routines, why not use the hardware serial library? If you set it to a high baud rate, it's pretty fast. As I understand things, you're not limited to 115200 baud. I think you'll have trouble doing things either faster or better.

At least now it'll be easier for them to read your code. It looks much better :)

Now that you have got the hang of posting code in tags would it be possible to see all of it ? What are these mysterious (to me at least) Timer objects ?

the reason I can't use Serial port is I have to do lot of works while I receive data, because I have to take analog reading every 100uS, same time save them on chip, I am doing it pretty well and I have extra time in that 100uS. so I am going to make protocol that sends one bit per 100uS so that I can share address of memory cards easily.

but if I use serial I think I have to wait until it receives, another reason is I can't use high buad rate since I use RF link, not wire, even I can't use virtual wire library,

I have implemented two type of protocol, I use one of them, now I am looking to measure pulse width with use of micros,

thanks

frechi91:
the reason I can’t use Serial port is I have to do lot of works while I receive data, because I have to take analog reading every 100uS, same time save them on chip, I am doing it pretty well and I have extra time in that 100uS. so I am going to make protocol that sends one bit per 100uS so that I can share address of memory cards easily.

Right, you want slow baud rates, not fast.

but if I use serial I think I have to wait until it receives,

There is a serial buffer that stores incoming bytes until you actually read them, you know?

another reason is I can’t use high buad rate since I use RF link, not wire, even I can’t use virtual wire library,

What sort of RF module? The ones that I use have a serial interface, and can communicate at up to 19200 baud. In fact, as long as <=256 bytes are sent at a time, baud rates of 115200 are possible. A break between transmissions is needed though, because the RF transmission rate is 19200. I use APC220 modules.