Basically It’s similar like a balancing machine.
Here a detail what I am doing and trying to achieve.
A 360ppr encoder running on 1500rpm. Also calculating its rpm in code.
A distance sensor measuring distance of A free floating shaft connected to a plate. Sensor output connected to ADS1115.
Encoder attached with a plate on which a circular weight can be placed. If plate is balance the output of sensor is max volt.
When unbalanced weight placed on top it will tell from which degree its not balanced
So I want to calculate all these things at a time.
Each and every "pulse" of a quadrature encoder causes a high-low and a low-high transition on each of the "A" and "B" outputs. So, for a 360 PPR encoder spinning at 1500 RPM: 1500 x 360 x 4 / 60 = 36,000 interrupts that must be serviced every second. That's pretty ambitious. Do you have just that part working by itself?
And yes, posting diagrams and code would probably help. Your verbal description is not very clear.
I am trying to work on a balancing system, that need to read signals (in form of voltage) and at the same time I should be able to read the encoder value (degree).
FreeRtos is something that seems be able to do it by using ESP32 multi-core feature, but as I am not familiar with it.
currently this is my configuration
ESP32
OMRON 360 pulse encoder having A,B,Z.
ADS1115 attached with SDA, SCL.
A voltage generator(sensor) is connecting to ADS1115.
Machine is running on 1350 RPM. A encoder and voltage generator attached with ESP32. while I am sending all the serially to my UI. (i.e. RPM calculation and the collected data)
If I stop reading ADS1115, on 1200-1350 RPM its skipping 2-5 pulses. but when I added reading ADC part, it start skipping 50-70 pulses of encoder.
Please any suggestion and help is highly appreciated, as this becomes a nightmare for me.
Is that skipping 2--5 pulses per rotation? I make the interrupt frequency 8100Hz, so you only have 120us to handle the interrupt.
Perhaps there's some other interrupt active that's taking significant time causing the encoder ones to be missed.
I'd suggest doing the adc reads in the main body of the code, using the phase information from the ISR to determine when to sample - yes there'll be some jitter to the readings, but it won't be slowing down the interrupt.
@smah still has not supplied a clear diagram of the setup, a schematic, complete code, or a coherent description of what he’s trying to do. These were all requested 2 months ago.
@MarkT. Yes it’s skipping 2-5 pulses per rotation if I disable adc read but some serial printing is enable with rpm calculation. But when I enable adc read it will skip 50-80 pulses. And I already doing adc read stuff in main loop.
@gfvalvo sorry for my late response as that project were halted for two months. Now again it’s started. I will share code once back home.
I still don't have a clear picture of what your machine is supposed to do. I guess that may not be important. Regarding the programming, you were already given several suggestions:
Use the ESP32 Exception Decoder to get more information from the back trace as to what tasks were executing when the crash occurred. Perhaps also follow up with Adafruit if the crash is occurring in their library.
Lighten the amount of work being done in the ISR and offload it to a FreeRTOS foreground task that would be activated by the ISR. You were given example code for this.
Confirm that your rotary encoder code is capable of handling the interrupt rate resulting from your 360 PPR encoder spinning at 1500 RPM.
Consider using ESP32's hardware pulse counter for the rotary encoder. You were given a link to the API page.
Which of the above items have you followed up on and what were the results? I have no further suggestions.
@gfvalvo based on your reply (above where you provide rtos code), As I said I am not able to understand how could I make a routine which enable to use hardware pulse counter (pcnt) for encoder as well as at the same time task for reading adc. As I am facing difficulty to understand that code. for eg: if I want to add my encoder in your given code, how can I do it?. At the same time my ADC is connect through SDA, SCL pins which is maintained by the Adafruit library. how can I read it with your given code. unfortunately I am not able to understand the configuration steps which I need to follow to write code using freeRtos.
If you can spare some time, I will be thankful.