Comments (3)
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.
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.
- PWM Motor
- 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.
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)
- Electron & pigpio: gpioInitialise is not a function HOT 2
- Error: The module '.../pigpio.node' was compiled against a different Node.js version HOT 4
- Unable to use package HOT 1
- Consider relaxing restrictions in binding.gyp HOT 8
- ask for help HOT 2
- Run stepper motor for a precise number of steps.
- Error: EINVAL, Invalid argument HOT 2
- how can i read data from gps from pin 15 tx 16 rx ? HOT 4
- using pigpio with 4 motors HOT 7
- High CPU usage on Pi 4B HOT 6
- Freeze when using invalid GPIO numbers HOT 1
- Issue w/ latest Node & OS HOT 1
- Could not locate bindings file HOT 22
- pigpio.gpioInitialise() in pi 4B HOT 12
- Is SPI slave mode supported? HOT 1
- "pigpio" error Maximum call stack size exceeded HOT 2
- Unable to start pigpio on RaspberryPi 3B+ - bullseye HOT 3
- Raspberry Pi 5 Support HOT 1
- Simply not working HOT 2
- Not working with lastest Raspberry pi OS 64bits (Bookworm) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pigpio.