# 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:

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

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.

##calculates different parameters for atmega328 and ds1307
##calculates values of twsr,twbr producing (only) integer
##SCL_frequencies.
##Results are in the file: "results.txt"
clear;
clc();
##myfile=fopen("setspeed1.txt","w");
diary results.txt
cpuclock=16e6;
prescalars=[1 4 16 64];
twbr=(0:1:255);
denom=16+(2*prescalars'*twbr);
frqscl=16e6./denom;