Hello,
Newbie with a first post here... We are using teensy 3.2 and have a simple function below to read PWM pulses:
We expect it to return a 32bit integer and we know the PWM pulse values it reads are around 1500. However, the function seems to returns the value of lowest byte (< 255) instead of 32bit integer. Can someone glance it over and let us know what we are doing wrong here? If we inline this function, it still returns the lowest byte. However if we move the for-loop into the main processing loop in our code and don't use a function call , then it works as expected (32bit integer value is obtained). I suspect there's something obviously wrong we done and hoping an extra pair of eyes can spot it, thanks!
-albertr
Newbie with a first post here... We are using teensy 3.2 and have a simple function below to read PWM pulses:
Code:
uint32_t read_afew( uint32_t howmany) {
uint32_t val = 0;
uint8_t i;
for (i = 0; i < howmany; i++) {
val=val+pulseIn(PWM_input,HIGH,21000);
}
return (val/howmany);
}
We expect it to return a 32bit integer and we know the PWM pulse values it reads are around 1500. However, the function seems to returns the value of lowest byte (< 255) instead of 32bit integer. Can someone glance it over and let us know what we are doing wrong here? If we inline this function, it still returns the lowest byte. However if we move the for-loop into the main processing loop in our code and don't use a function call , then it works as expected (32bit integer value is obtained). I suspect there's something obviously wrong we done and hoping an extra pair of eyes can spot it, thanks!
-albertr