0

I am using a Teensy 3.2 board as control logic for an ADC that I am building for teaching purposes. Currently, I am employing an attachInterrupt() to detect the rising edge of an external clock pulse used to clock the entire system.

The system works great. However, it seems my method below for converting the binary string to decimal is too slow and does not convert values fast enough before the next clock-pulse.

Looking for some input.

Code:

byte convertBinToDec() {
  byte result = 0;
  for(int i = 0; i < numBits; i++) {
    result |= masterBinCountIn[(11-i)] << i;
  }
  return result;
}
  • interrupts use a lot more clock pulses and you cant have an interrupt in every clock. in your setup you are missing a lot of rising edges that way. the minimum clock pulses for "one" interrupt (just the interrupt itself) varies between 5 to 20 clock cycles in various microcontrollers. so [optimistically] your code inside interrupt needs above 50 clocks to run just for once! – Tirdad Sadri Nejad Apr 19 at 20:26
  • @TirdadSadriNejad I don't think, that the OP really clocks the Teensy with that signal, but only executes his code on the rising edge of the signal. – chrisl Apr 19 at 20:51
  • How fast is your clock signal? And why do you even want to do this? currently you simply copy each bit individally into the result. Why don't use the data directly? What do you try to do with this function? – chrisl Apr 19 at 20:51
  • This function returns a number in binary (not decimal) format. You are not converting anything to decimal. – Edgar Bonet Apr 19 at 20:55
  • why do you need to convert binary to decimal? – jsotola Apr 19 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.