Choosing values

A formula may contain two-or more variables. Every variable can take many values. We can choose specific values which suit our need. एखाद्या सूत्रात दोन किंवा त्यापेक्षा जास्त चले असू शकतात. त्यामुळे येणाऱ्या अनेक उत्तरांतून आपल्याला हवे ती उत्तरे शोधणे महत्वाचे ठरते. त्यासाठी Gnu-Octave चा वापर करणे आवश्यक ठऱते. या साठी पुढील उदाहरण अभ्यासणे योग्य ठरेल.  

Twi communication using AVR

Atmega AVR devices (like Atmega328 used in Arduino) can read and write to the external TWI  enabled devices like (twi eeprom memories, real time calendar chips etc). To decide the speed of communication, this formula is used:

$latex SCL \ frequency = \frac{CPU \ clock \ frequency}{16+2(TWBR).(prescalar \ value)}&s=2$

Suppose we want to find all possible values of the SCL frequency. They will depend upon:

  1. TWBR value which is between 0 to 255. So 256 different values are possible.
  2. Pre-scalar values which are 1,4,16 and 64. These are four possible values for corresponding twsr values 0,1,2,3.

This shows that SCL frequency will have 256*4 =1024 values. Out of these we are interested in all integer values say. Here we use Gnu-Octave….

The Octave script

The following Octave-script produces a file results.txt which lists all chosen integer values (43 out of 1024) of SCL frequency, and corresponding values of twsr and twbr registers.

[code language=”matlab”]
##calculates different parameters for atmega328 and ds1307
##calculates values of twsr,twbr producing (only) integer
##Results are in the file: "results.txt"
diary results.txt
prescalars=[1 4 16 64];
select=!(frqscl-round(frqscl));##integer values made nonzero
sclint=vec(frqscl.*select);##only integer values in the vector,
##Now display the results.
disp([" twsr "," twbr ","scl_frequency"]);
disp([twsr twbr’ scl_frequency]);
diary off

This entry was posted in SciTech. Bookmark the permalink.