Pages: 1 [2]   Go Down
Author Topic: Pin output toggling error.......signal tearing?  (Read 798 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have to protect the transmission, you may want to think what it is that you are trying to protect: you can protect the pulse width (high or low, or high and low); you can protect every 8 pulses; or you can protect all 24 pulses.

That will determine where / when  you disable / re-enable the interrupts.

The key is to minimize the duration of disabling them.

...Meaning put it in "for" loop where u need it?
Code:
for(int j=0;j <5; j++)
     { cli();
       ....
       .....
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 495
Posts: 19032
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yes it disables all Interrupts...

It disables entry into an interrupt service routine. In other words, the servicing of interrupts. However as dhenry said, if an interrupt "event" occurs (eg. a timer overflows) then that will be remembered and processed (in interrupt priority order) next time interrupts are enabled.
Logged


Global Moderator
Online Online
Brattain Member
*****
Karma: 495
Posts: 19032
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...Meaning put it in "for" loop where u need it?

In your case, I wouldn't be disabling interrupts. You are trying to solve a problem the wrong way by doing that.
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick;

 That's a very impressive application of a timer. I have a few questions:

1. Can the OCR2A&B registers be changed 'on the fly' to other values without having to do anything else?
2. What would the max and min frequencies be on a standard 16 Mhz board with retaining @ 50% duty cycle?
3. What would be the commands to stop the timer at any time, and to restart it at any time.

Sure seems like this could be made into a nice simple general purpose function clock generator?

Lefty


Lefy,
Absolutely this is what I was thinking , these Timer/Counter are great piece of kits that can be used in many more ways!
Also thanks Nick for answering the questions.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes it disables all Interrupts...

It disables entry into an interrupt service routine. In other words, the servicing of interrupts. However as dhenry said, if an interrupt "event" occurs (eg. a timer overflows) then that will be remembered and processed (in interrupt priority order) next time interrupts are enabled.

Nick,
These Timer/ Counters are great piece of kits but not much focus or references are available.
Why don't you make a guide specific to atmega328 & 32u4 for Arduino users about Timers/Counters??

P.S. would like to help you out in terms of preparing Graphics & illustrations.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That will determine where / when  you disable / re-enable the interrupts.

A general rule I try to follow is to use interrupts only where necessary, and when using interrupts disable them only where necessary.

By default interrupts are Enable in Arduino, isn't it? Thats why I was getting errors. Also whenever one use Serial.Read/Write function or Delay() interrupts are Enabled, isn't it??
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 495
Posts: 19032
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick,
These Timer/ Counters are great piece of kits but not much focus or references are available.
Why don't you make a guide specific to atmega328 & 32u4 for Arduino users about Timers/Counters??

I have quite a bit of detail here:

http://www.gammon.com.au/forum/?id=11504
Logged


Global Moderator
Online Online
Brattain Member
*****
Karma: 495
Posts: 19032
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

By default interrupts are Enable in Arduino, isn't it? Thats why I was getting errors. Also whenever one use Serial.Read/Write function or Delay() interrupts are Enabled, isn't it??

Yes interrupts are enabled by default. PeterH was saying, I think, that adding your own interrupt handlers should only be done if necessary.

However the default (enabled) interrupts are used for millis(), micros(), delay(). Also they are used for serial reading and writing.
Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
[quote]..Meaning put it in "for" loop where u need it?[/quote]

It depends.

The following protects the width of '1':

[code]
  cli();
  clk_set();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  sei();
  clk_clr();
  ...

or you can expand to protect the period of a transition:

Code:
  cli();
  clk_set();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  //sei();
  clk_clr();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  sei();

Or to protect all 24 transmission:
  cli();
  for (i=0; i<24; i++) {
    clk_set();
    NOP();...
    clk_clr();
    NOP();...
  }
  sei();
[/code]

...

All depends on what you are trying to do.
Logged

Pages: 1 [2]   Go Up
Jump to: