I'm sure the problem is caused by pulsein, because when I remove the codes here, it works fine. Instead of pulsein, is there another way I can read PWM values?
The linked instructabke makes no mention of an RC receiver, nor decoding PWM values.
Please describe your project.
A block diagram of how the parts are interconnected woukd be a start to what may be more useful, a schematic diagram.
Post the code that works, but becomes unstable. I have seen some simple code using pukseIn(), usually with the additional timeout parameter filled in so things keep moving along.
Does your receiver have a PPM output capability? There are libraries that can listen to PPM and derive all N channels data, typically presenting to the higher level software as values between 1000 and 2000.
I have no problem reading PWM values, that is, I can easily read the values from the receiver with the same codes.
However, as far as I understand, it performs tilt compensation every 500 milliseconds.
When reading PWM values, the slope compensation waiting time becomes longer due to interruptions of the pulse function and it cannot provide stable operation here.
There is nothing about PWM in the link in question. I'm working on it to be used in an Autopilot project I'm trying to develop.
Through the RC transceiver, it will need to take action according to the PWM value coming from the receiver (power the engine, direct the vehicle, etc.).
However, as soon as I define the channels coming from the receiver (pulse), unfortunately the tilt compensation does not work.
I am reading pulsein values every 50milliseconds. But this time, the values I send from the transmitter go to the other side intermittently. For example, while driving the servo, it moves intermittently.