Git Product home page Git Product logo

Comments (3)

fivdi avatar fivdi commented on August 16, 2024

I have found that if I disable PWM or write MAX PWM for the motors the encoder interrupts work fine.

If I understand this statement correctly, it means that whether or not things function correctly depends on the value passed to pwmWrite. Is this correct? If so, I don't have an explanation of how this could effect whether or not interrupts are caught timely.

Normally, if interrupts are not being handled timely, it would indicate that other code is running when the interrupt occurs and this other code must run to completion before the interrupt handler is executed.

It's very difficult to say much here without a simple test case that can be used to reproduce the problem.

from pigpio.

afnan avatar afnan commented on August 16, 2024

The test case would be but tricky to produce as it will depend on the interrupt trigger. The test program I have only had two functions.

  1. PWM Motor
  2. Monitor Encoders (single interrupt at enA)

Now, if I disable PWM, or do digital write on the motor control pin or use 255 the encoder interrupts work fine. The algorithm for monitoring encoders consists of an if-else within the interrupt call and checks compares the level (of the int causing pin) and digitalRead of another pin to determine the direction of motion https://howtomechatronics.com/uncategorized/rotary-encoder-works-use-arduino/. I can go in more detail.

What I think is happening is that Pi does PWM and as its software PWM the processor does not address the interrupts timely.

For now to get the distance readings I have disabled speed and just write 255 and everything is working fine

from pigpio.

fivdi avatar fivdi commented on August 16, 2024

The algorithm for monitoring encoders consists of an if-else within the interrupt call and checks compares the level (of the int causing pin) and digitalRead of another pin to determine the direction of motion...

For timely interrupt processing, it's not really that important how long the interrupt handler itself executes. I would imagine that your interrupt routine is running fast. I would also imagine that there are not very many interrupts per second. I would expect the interrupt handler itself to be fine. What is much more important is what the JavaScript engine is doing at the instant the interrupt occurs. Don't forget, in JavaScript there is one thread that does everything. If the JavaScript engine is running application code at the instant the interrupt occurs, it will first run that code to completion before returning to the event loop thus giving the interrupt handler a chance to execute. To handle interrupts timely, everything needs to be quite fast, not just the interrupt handler. For example, if the program has synchronous code somewhere that runs for 250 milliseconds, and a hardware interrupt occurs 1 millisecond after that synchronous code starts running, then there will be at least a 249 millisecond delay before the interrupt handler is executed. The slowest synchronous code in the application will determine how timely interrupts are handled.

What I think is happening is that Pi does PWM and as its software PWM the processor does not address the interrupts timely.

This isn't how it works. pigpio uses a DMA hardware peripheral on the Pi to generate PWM pulses. It doesn't use software to generate the pulses. Note that if you feel that the problem is related to how pigpio uses DMA to generate PWM pulses, you could switch to using classical hardware generated PWM pulses using hardwarePwmWrite to see if it helps.

from pigpio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.