Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //measure rc time to charge to '1' on RC_READ pin
- uint32_t rctmr_get(uint8_t ch_pin) {
- uint32_t tmp;
- IO_IN(RC_DDR, ch_pin); //discharge. ch_pin idles high/input
- IO_OUT(RC_DDR, RC_READ); //discharges the capacitor (RC_READ idles low/output)
- while (IO_GET(RC_PORTIN, RC_READ)) continue; //until the capacitor is fully discharged
- IO_OUT(RC_PORT, ch_pin); //start to charge through the ch_pin
- IO_IN(RC_DDR, RC_READ); //start to charge up the capacitor
- tmp = ticks(); //time stamp tmp
- while (IO_GET(RC_PORTIN, RC_READ)==0) continue; //wait for READ pin to go high
- tmp = ticks() - tmp; //measure the time elapsed
- IO_OUT(RC_DDR, RC_READ); //discharge the capacitor
- IO_IN(RC_DDR, ch_pin); //start to discharge from the charge pin (idles high / input)
- return tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement