Go Down

Topic: OneWire + Servo not possible? (Read 495 times) previous topic - next topic

Thomas33

I want to read temperature from DS1820 with the arduino OnwWire library, and drive a servo motor with the arduino Servo library, but this seems impossible:

In the arduino library OneWire.cpp it says in the header comments
  "Disable interrupts during timing critical sections"

and there is a code section in OneWire::write_bit:
      noInterrupts();
      DIRECT_WRITE_LOW(reg, mask);
      DIRECT_MODE_OUTPUT(reg, mask);   // drive output low
      delayMicroseconds(65);
      DIRECT_WRITE_HIGH(reg, mask);   // drive output high
      interrupts();

So I believe, that interrupts are disabled for at least 65 us now and then.

On the other hand, if interrupts are delayed for 65 us in ther Servo.cpp, the pulse for the servo might get stretched for this period. As 1000 us roughly do 180 degree, this would be around 10 degree. That is quite a bit too much to be ignored.

My solution idea was to disable the servo pulsing, while reading the DS1820, but IMHO this wont work either:

In Servo.cpp the is a function detach(). That one tests isTimerActive(timer) and then calls finISR. (I understand the "isTimerActive(timer)" that way, that it just checks, if that timer is responsible for any further servos, but does
not check, if a servo is just getting its timing pulse.) So IMHO that function imediately stops the timer from sending any more interrupts. So, if the servo output was just sending the pwd signal, that signal will get corrupted. So the last position info the servo receives is completely wrong.

Another problem is, that when activating the servo again, I cannot give a starting value right away, so the servo will do another "jump".

Does anybody have thoughts (or solutions) for this?

Thanks for answers in advance,
Thomas
A mouse is a device to point at the xterm you want to type in.

johnwasser


Another problem is, that when activating the servo again, I cannot give a starting value right away, so the servo will do another "jump".


You can do myServo.write(); before myServo.attach(); to set the initial position.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Thomas33

Quote

You can do myServo.write(); before myServo.attach(); to set the initial position.


Yes, you are right. So this particular problem does not exist.

The bad news: Not only, that detach() may fall into an ongoing pulse, but attach() may do too. Probably for the attach() the problem is more of theoretical nature, as 20 ms later the servo will receive a proper (untruncated) pulse, and everything is fine from then on.

Still, the potential truncated last pulse at detach() is imho a serious problem.

I want to suggest to insert a wait-until-pin-notpulsing (I think its a negative pulse, but not sure, thats why I use this vague term "notpulsing"), at the beginning of detach() and by the way into attach() too.

Are the are reasons against it, or shall I do it, or does anybody else like to? (I prefer 3th possibility ;-)

Thomas




A mouse is a device to point at the xterm you want to type in.

theinlinaung2010

Did you solve the problem Thomas? I am encountering the same problem as you. The servo would go around some degree while reading temperature. I'd be glad to hear from you.
Thein Lin Aung

Go Up