0
$\begingroup$

I'm working to develop a function in my embedded code for i2c initialization.

I came up to this equation which is to calculate the speed of the i2c clock.

But if I want to develop a function that takes a user popular numbers for speed then I have to change the shape of the equation to get that variable in place to receive users values for adjusting the speed.

This is the equation:

$$\mathrm{SCL\ frequency}=\frac{\mathrm{CPU\ Clock\ frequency}}{16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}}$$

I want to take out TWBR instead of SCL frequency. I tried to do it on a paper but I don't know how to take it out, from the multiple PrescalerValue and the addition of 16??!

$\endgroup$
  • 1
    $\begingroup$ Multiply both sides by the denominator, move the SCL term to the right member and divide by the coefficient of TWBR. $\endgroup$ – Yves Daoust Apr 19 at 9:24
  • $\begingroup$ You may take reciprocals, multiply by CPU, subtract $16$ and finally divide by $2$PrescalerBValue. $\endgroup$ – Michael Hoppe Apr 19 at 9:30
  • $\begingroup$ OK, thank you so much :) $\endgroup$ – Perch Eagle Apr 19 at 9:32
  • $\begingroup$ @MichaelHoppe OK, thanks :) $\endgroup$ – Perch Eagle Apr 19 at 9:32
  • $\begingroup$ Sorry guys didn't know how to do it! $\endgroup$ – Perch Eagle Apr 19 at 9:47
0
$\begingroup$

$$\mathrm{SCL\ frequency}=\frac{\mathrm{CPU\ Clock\ frequency}}{16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}}$$

Multiply both sides by $16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}$, and divide both sides by $\mathrm{SCL\ frequency}$:

$$16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}=\frac{\mathrm{CPU\ Clock\ frequency}}{\mathrm{SCL\ frequency}}$$

Subtract $16$ from both sides:

$$2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}=\frac{\mathrm{CPU\ Clock\ frequency}}{\mathrm{SCL\ frequency}}-16$$

Divide both sides by $2\ \mathrm{Prescaler\ Value}$:

$$\mathrm{TWBR}=\frac{\mathrm{CPU\ Clock\ frequency}}{2\ \mathrm{SCL\ frequency}\ \cdot\ \mathrm{Prescaler\ Value}}-\frac{8}{\mathrm{Prescaler\ Value}}$$

$\endgroup$
  • $\begingroup$ Your answer is more better and arranged, thanks for the help :) $\endgroup$ – Perch Eagle Apr 20 at 8:51
  • $\begingroup$ I removed my answer, thanks again. $\endgroup$ – Perch Eagle Apr 20 at 8:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.