Thread: tuner programming

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    37

    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. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You'd best show some code to show what you mean.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    37
    Quote Originally Posted by iMalc View Post
    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


    Last edited by kim15; 03-25-2013 at 12:19 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    37
    Quote Originally Posted by Salem View Post
    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. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    37

    Smile

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 01:03 AM
  2. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  3. Media Center not recognizing Digital Tuner
    By kryptkat in forum Tech Board
    Replies: 1
    Last Post: 04-17-2009, 10:46 AM
  4. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  5. TV tuner
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-01-2001, 12:00 AM