Changeset 215


Ignore:
Timestamp:
Nov 7, 2010 12:18:48 AM (7 years ago)
Author:
df9dq
Message:

Schwerer Fehler bei Frequenzeinstellung beseitigt (hin und wieder sprang der Si570 auf Factory Defaults).
Neuer USB-String für Hersteller (siehe Lizenzbedingungen von Objective Development).
Auslesen der Factory-Default-Frequenz, ermöglicht automatischen Quarzabgleich mit Rockprog.

Location:
trunk/Software/LPC
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Software/LPC/fifisdr/src/i2c/si570.c

    r176 r215  
    5757     * the frequency of the host by the automatically selected prescaler. 
    5858     */ 
    59 static uint32_t si570_anchor_frequency; 
     59static uint32_t si570_anchorFrequency; 
     60    /* Value of HS_DIV at anchor frequency */ 
     61static uint8_t si570_anchorHsDiv; 
     62    /* Value of N1 at anchor frequency */ 
     63static uint8_t si570_anchorN1; 
    6064    /* Current prescaler setting (1, 4, 16, 64) */ 
    6165static uint32_t si570_current_prescaler; 
     
    6468    /* Current content of virtual Si570 registers 7...12 */ 
    6569static uint8_t si570_vregs[6]; 
     70    /* Content of Si570 registers after power-up (factory defaults) */ 
     71static uint8_t si570_factory_default_regs[6]; 
    6672 
    6773 
     
    492498{ 
    493499    uint32_t hs_div; 
    494     uint32_t hs_div_reg; 
    495500    uint32_t n1; 
    496501    uint64_t rfreq; 
     
    500505    uint32_t freq; 
    501506    uint32_t prescaler; 
     507    uint8_t regValue; 
    502508 
    503509 
     
    506512 
    507513    /* Find the required prescaler (no change yet) */ 
    508     si570_set_prescaler( frequency, &prescaler ); 
     514    si570_set_prescaler(frequency, &prescaler); 
    509515    freq = frequency * prescaler; 
    510516 
    511517    /* VHF frequencies: Use 3rd/5th harmonic */ 
    512     if (frequency >= g_params.freq_5th_harmonic) 
    513     { 
     518    if (frequency >= g_params.freq_5th_harmonic) { 
    514519        freq = freq / 5; 
    515520    } 
    516     else if (frequency >= g_params.freq_3rd_harmonic) 
    517     { 
     521    else if (frequency >= g_params.freq_3rd_harmonic) { 
    518522        freq = freq / 3; 
    519523    } 
    520524 
    521525    /* Find optimum post dividers */ 
    522     if (!si570_find_hsdiv_n1( freq, &hs_div, &n1, true )) 
     526    if (!si570_find_hsdiv_n1(freq, &hs_div, &n1, true)) 
    523527        return; 
    524528 
     
    535539 
    536540    /* Prepare message for I2C bus */ 
    537     hs_div_reg = hs_div - 4; 
    538541    txbuf[0] = 7; 
    539     txbuf[1] = ((hs_div_reg & 0x07) << 5) | (((n1-1) >> 2) & 0x1F); // Reg 7 
     542    txbuf[1] = (((hs_div-4) & 0x07) << 5) | (((n1-1) >> 2) & 0x1F); // Reg 7 
    540543    txbuf[2] = (((n1-1) & 0x03) << 6) | ((rfreq >> 32) & 0x3F);     // Reg 8 
    541544    txbuf[3] = ((rfreq >> 24) & 0xFF);                              // Reg 9 
     
    545548 
    546549    /* Check if we can use "smooth tuning" */ 
    547     delta_f = (int32_t)freq - (int32_t)si570_anchor_frequency; 
     550    delta_f = (int32_t)freq - (int32_t)si570_anchorFrequency; 
    548551    if( delta_f < 0 ) 
    549552        delta_f = -delta_f; 
     
    553556     */ 
    554557    smooth = 
    555         delta_f <= ((g_params.smoothtune * (int64_t)si570_anchor_frequency) >> 20); 
     558        delta_f <= ((g_params.smoothtune * (int64_t)si570_anchorFrequency) >> 20); 
     559    /* Smooth tuning is only possible if HS_DIV and N1 do not change. */ 
     560    smooth = smooth && (hs_div == si570_anchorHsDiv) && (n1 == si570_anchorN1); 
    556561 
    557562    /* Smooth tuning requires to update the RFREQ registers only. 
     
    559564     * case the frequency becomes the new anchor. 
    560565     */ 
    561     if( smooth ) 
    562     { 
     566    if (smooth) { 
    563567        txbuf[1] = 8; 
    564         si570_write_buffer( &txbuf[1], 6 ); 
    565     } 
    566     else 
    567     { 
    568         si570_write_reg( 137, 0x20 );     // Freeze 
    569         si570_write_buffer( &txbuf[0], 7 ); 
    570         si570_write_reg( 137, 0x00 );     // Unfreeze 
    571         si570_write_reg( 135, 0x40 );     // NewFreq 
    572  
    573         si570_anchor_frequency = freq; 
     568        si570_read_reg(135, &regValue); 
     569        regValue |= 0x20; 
     570        si570_write_reg(135, regValue);     /* Freeze M = 1 */ 
     571        si570_write_buffer(&txbuf[1], 6); 
     572        si570_read_reg(135, &regValue); 
     573        regValue &= ~0x20; 
     574        si570_write_reg(135, regValue);     /* Freeze M = 0 */ 
     575    } 
     576    else { 
     577        si570_read_reg(137, &regValue); 
     578        regValue |= 0x10; 
     579        si570_write_reg(137, regValue);     /* Freeze */ 
     580        si570_write_buffer(&txbuf[0], 7); 
     581        si570_read_reg(137, &regValue); 
     582        regValue &= ~0x10; 
     583        si570_write_reg(137, regValue);     /* Unfreeze */ 
     584        si570_write_reg(135, 0x40);         /* NewFreq */ 
     585 
     586        si570_anchorFrequency = freq; 
     587        si570_anchorHsDiv = hs_div; 
     588        si570_anchorN1 = n1; 
    574589    } 
    575590 
    576591    /* Set the prescaler */ 
    577     si570_set_prescaler( frequency, NULL ); 
    578  
    579     si570_regs[0] = ((hs_div_reg & 0x07) << 5) | (((n1-1) >> 2) & 0x1F); 
    580     si570_regs[1] = (((n1-1) & 0x03) << 6) | ((rfreq >> 32) & 0x3F); 
    581     si570_regs[2] = ((rfreq >> 24) & 0xFF); 
    582     si570_regs[3] = ((rfreq >> 16) & 0xFF); 
    583     si570_regs[4] = ((rfreq >> 8) & 0xFF); 
    584     si570_regs[5] = (rfreq & 0xFF); 
     592    si570_set_prescaler(frequency, NULL); 
     593 
     594    /* Read back current registers */ 
     595    si570_read_registers(); 
    585596} 
    586597 
     
    644655    si570_current_frequency = 0;    /* This forces a full register load on first frequency set */ 
    645656    si570_current_prescaler = 1; 
    646     si570_anchor_frequency = 0; 
     657    si570_anchorFrequency = 0; 
     658    si570_anchorHsDiv = 0; 
     659    si570_anchorN1 = 0; 
    647660 
    648661    /* Initialize I2C */ 
     
    651664    /* Auto-detect the Si570 I2C address */ 
    652665    si570_detect_i2c_address(); 
     666 
     667    /* Read factory defaults */ 
     668    si570_read_registers(); 
     669    si570_factory_default_regs[0] = si570_regs[0]; 
     670    si570_factory_default_regs[1] = si570_regs[1]; 
     671    si570_factory_default_regs[2] = si570_regs[2]; 
     672    si570_factory_default_regs[3] = si570_regs[3]; 
     673    si570_factory_default_regs[4] = si570_regs[4]; 
     674    si570_factory_default_regs[5] = si570_regs[5]; 
    653675 
    654676    message.opcode = SI570_OPCODE_SET_FREQUENCY; 
     
    679701            break; 
    680702 
     703            case SI570_OPCODE_GET_FACTORY_STARTUP_REGISTERS: 
     704                /* Send the factory default registers */ 
     705                usbcontrol_send_ep0(6, &si570_factory_default_regs[0]); 
     706            break; 
     707 
    681708            case SI570_OPCODE_SET_VIRTUAL_REGISTERS: 
    682709                /* Update the virtual registers, and adjust the real frequency accordingly. */ 
  • trunk/Software/LPC/fifisdr/src/i2c/si570.h

    r171 r215  
    3232 
    3333 
    34 #define SI570_OPCODE_SET_FREQUENCY              (1) 
    35 #define SI570_OPCODE_GET_VIRTUAL_REGISTERS      (2) 
    36 #define SI570_OPCODE_GET_REAL_REGISTERS         (3) 
    37 #define SI570_OPCODE_SET_VIRTUAL_REGISTERS      (4) 
    38 #define SI570_OPCODE_SET_REAL_REGISTERS         (5) 
    39  
     34#define SI570_OPCODE_SET_FREQUENCY                  (1) 
     35#define SI570_OPCODE_GET_VIRTUAL_REGISTERS          (2) 
     36#define SI570_OPCODE_GET_REAL_REGISTERS             (3) 
     37#define SI570_OPCODE_SET_VIRTUAL_REGISTERS          (4) 
     38#define SI570_OPCODE_SET_REAL_REGISTERS             (5) 
     39#define SI570_OPCODE_GET_FACTORY_STARTUP_REGISTERS  (6) 
    4040 
    4141 
  • trunk/Software/LPC/fifisdr/src/lpcusb/softrock.c

    r203 r215  
    243243                *piLen = 4; 
    244244            break; 
     245            case 12: 
     246                /* Read Si570 factory startup register values */ 
     247                si570_message.opcode = SI570_OPCODE_GET_FACTORY_STARTUP_REGISTERS; 
     248                xQueueSendToBackFromISR (xSi570Queue, &si570_message, &TaskWoken); 
     249                *piLen = -1; 
     250            break; 
    245251            default: 
    246252                return false; 
  • trunk/Software/LPC/fifisdr/src/lpcusb/usbdesc.c

    r203 r215  
    217217 
    218218    /* #1: Device idVendor */ 
    219     8, USBD_STRING, 
    220     'O', 0, 
    221     '2', 0, 
    222     '8', 0, 
     219    42, USBD_STRING, 
     220    'w', 0, 
     221    'w', 0, 
     222    'w', 0, 
     223    '.', 0, 
     224    'o', 0, 
     225    'v', 0, 
     226    '-', 0, 
     227    'l', 0, 
     228    'e', 0, 
     229    'n', 0, 
     230    'n', 0, 
     231    'e', 0, 
     232    's', 0, 
     233    't', 0, 
     234    'a', 0, 
     235    'd', 0, 
     236    't', 0, 
     237    '.', 0, 
     238    'd', 0, 
     239    'e', 0, 
    223240 
    224241    /* #2: Device idProduct */ 
Note: See TracChangeset for help on using the changeset viewer.