1. ## tuner programming

greetings programming masters,

i have this task on hand, which requires me to show different freq for each channels i have. like ch1=98.1, ch2=95.1, etc up to 6 channels. but i still need to keep the range for the fm freq (87.5MHz-108.0MHz)

currently i am just defining the freq to be as following

Code:
```#define FM_LOW1   981
#define FM_LOW2   951

#define FM_LMT     1080

#define FM_MAX1   (FM_LMT - FM_LOW1)*2
#define FM_MAX2   (FM_LMT - FM_LOW2)*2```
which is actually wrong, because since i have defined the lowest values for each channel to be 98.1MHz and 95.1MHz respectively, I cant access the freq from 87.5MHz - 98.0MHz (for ch 1) and 87.5MHz - 95.1MHz (for ch 2)

is there any other ways to do this?

2. You'd best show some code to show what you mean.

3. Originally Posted by iMalc
You'd best show some code to show what you mean.

yes. here it is.

Code:
```#define FM_LOW_1    981
#define FM_LOW_2    950
#define FM_LMT       1080
#define FM_MAX_1     (FM_LMT - FM_LOW_1)```
Code:
```
#define FM_MAX_2     (FM_LMT - FM_LOW_2)

switch (ra_getRaBand()){
case FM1:
switch (ra_getPCH())
{
case 0:
break;
case 1:
return FM_MAX_1;
case 2:
return FM_MAX_2;
default:
return _FM_MAX_1;
}
case FM2:
return  FM_MAX_1;
case FM3:
return  FM_MAX_1;
default:
return  FM_MAX_1;
}
```

if by using this way, of course it will "work", because it will show the frequency wanted, because i set it to be the lowest. but as i mentioned earlier, i dont have the freq of below 98.1 or 95.0

4. Perhaps
Code:
```#define FM_LOW 875
#define FM_HIGH 1080

struct chan {
char *name;
int low;
int high;
} channels[] = {
{ "ch1", 980, 982 }, // 98.0 to 98.2
};```
You can vary the frequency between FM_LOW and FM_HIGH
Then search your table to determine if that corresponds to a known channel.

5. Originally Posted by Salem
Perhaps
Code:
```#define FM_LOW 875
#define FM_HIGH 1080

struct chan {
char *name;
int low;
int high;
} channels[] = {
{ "ch1", 980, 982 }, // 98.0 to 98.2
};```
You can vary the frequency between FM_LOW and FM_HIGH
Then search your table to determine if that corresponds to a known channel.

the struct that u made, does it mean that it will only go from 98.0 - 98.2?

im not very familiar with structs and not good with it.

6. Do you want to scan the whole frequency range, and be able to tell if you're on a channel?

Or do you just want to jump from one channel to another, possibly with the ability to do a bit of fine tuning?

> im not very familiar with structs and not good with it.
Consider this an opportunity to learn something then.

7. Im sorry. perhaps i didnt explain it correctly.

Code:
```#define FM_MAX_1    (FM_LMT - FM_LOW_1)*2        // for ch 1
#define FM_MAX_2    (FM_LMT - FM_LOW_2)*2        // for ch 2

#define FM_LMT        1080        // for all ch available

#define FM_LOW_2    879        // for ch 1
#define FM_LOW_3    981        // for ch 2

static uint max (void);
static uint min (void);

static uint max (void)
{
switch (ra_getRaBand())
{
case FM1:
switch (ra_getPCH())
{
case 0:
break;
case 1:
return FM_MAX_1;
case 2:
return FM_MAX_2;
default:
return FM_MAX_1;
}
case FM2:
return FM_MAX_1;
case FM3:
return FM_MAX_1;
default:
return FM_MAX_1;
}
}

static uint min (void)
{
switch (ra_getRaBand())
{
case FM1:
switch (ra_getPCH())
{
case 0:
break;
case 1:
return FM_LOW_1;
case 2:
return FM_LOW_2;
default:
return FM_LOW_1;
}
case FM2:
return FM_LOW_1;
case FM3:
return FM_LOW_1;
default:
return FM_LOW_1;
}
}

/*the FM range must start from 87.5MHz and ends at 108.0MHz, therefore the FM_LMT is the highest fm range and FM_LOW is the lowest fm range.
Initially, the program has #define FM_LOW    875, and will display on LCD as 87.5MHz. Now the task is to change it to have different frequencies on each channels
once the tuner is turned on. By using the method above, I am missing the low frequency (87.5MHz until what is set to be the lowest FM range, in this case,
until 87.9MHz and 98.1MHz*/```
And thanks for the note. I will look up for structs and study it as well