Changeset - 639ea4c6e941
[Not reviewed]
default
0 1 0
Ethan Zonca - 8 years ago 2017-09-24 16:58:46
ez@ethanzonca.com
Altitude seems to work correctly now!
1 file changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/wspr.c
Show inline comments
 
@@ -51,50 +51,51 @@ void wspr_wakeup(void)
 
    HAL_TIM_Base_Start_IT(&htim1);
 
}
 

	
 

	
 
// Bring up TCXO and oscillator IC
 
void wspr_transmit(uint8_t* grid_locator, uint8_t send_alternate)
 
{
 
	// Copy 4 digit grid locator to local buffer; null terminate
 
	for(uint8_t i=0; i<4; i++)
 
		loc[i] = grid_locator[i];
 
	loc[4] = '\0';
 

	
 
    // Set power to altitude in m / 150
 
    uint8_t altscaled = gps_getdata()->altitude / 150;
 
    if(altscaled > 60)
 
        altscaled = 60;
 

	
 

	
 
    // If alternate packet, send 0XFXXEN82XX
 
    if(send_alternate)
 
    {
 
        /////////////////////////////////////////////////
 
        // Composite altitude and sub-maidenhead locator
 
        ///////////////////////////////////////////////// 
 
        uint16_t maiden_ext = (loc[4] - 'A') + ((loc[5] - 'A') * 24); // 0-575
 
        uint16_t altitude_mod = gps_getdata()->altitude / 20;   
 
        // Use untrimmed locator
 
        uint32_t maiden_ext = (grid_locator[4] - 'A') + ((grid_locator[5] - 'A') * 24); // 0-575
 
        uint32_t altitude_mod = gps_getdata()->altitude / 20;   
 

	
 
        // Ciel at 21,340 meters
 
        if(altitude_mod > 1067)
 
            altitude_mod = 1067; // Don't overflow into maidenhead!
 
    
 
        // Compose composite altitude (lsbs) with maidenhead locator (msbs)
 
        uint32_t subalt = (1068 * maiden_ext) + (gps_getdata()->altitude / 20);
 

	
 

	
 

	
 
        ////////////////////////////////////////////
 
        // Encode extended maidenhead and altitude
 
        ////////////////////////////////////////////
 

	
 
        // Static set first char: balloon ID (invalid call)
 
        call[0] = '0';
 

	
 
        // Split into chunks of valmax 36, 26, 26, 26
 

	
 
        // Mask off following 3 26valmax fields
 
        uint32_t chunk = subalt / 26 / 26 / 26; 
 

	
 
        // Encode to callsign
 
        if(chunk < 10)
 
@@ -210,48 +211,51 @@ void wspr_transmit(uint8_t* grid_locator
 
        call[1] = call_orig[1];
 
        call[2] = call_orig[2];
 
        call[3] = call_orig[3];
 
        call[4] = call_orig[4];
 
        call[5] = call_orig[5];
 
        call[6] = call_orig[6];
 

	
 
        dbm = DBM_ORIG; 
 
    }
 

	
 
    // Start timer for WSPR
 
    __TIM1_CLK_ENABLE();
 
    htim1.Instance = TIM1;
 
    htim1.Init.Prescaler = 512 / 4; // FIXED gives 64us ticks from 2mhz clock // gives 64uS ticks from 8MHz ahbclk
 
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 
    htim1.Init.Period = ctc; // Count up to this value (how many 64uS ticks per symbol)
 
    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 
    htim1.Init.RepetitionCounter = 0;
 
    HAL_TIM_Base_Init(&htim1);
 
    HAL_TIM_Base_Start_IT(&htim1);
 
    HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0, 0);
 
    HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 

	
 

	
 

	
 
    // TODO: Bring up TCXO sooner! Gotta let it warm up or something
 

	
 
    HAL_GPIO_WritePin(OSC_NOTEN, 0);
 
    HAL_GPIO_WritePin(TCXO_EN, 1);
 
    HAL_Delay(100);
 

	
 
    // Bring up the chip
 
    i2c_init();
 
    si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
 
    si5351_set_correction(0);
 
    //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
    //si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
    si5351_set_freq(WSPR_DEFAULT_FREQ * 100, 0, SI5351_CLK0);
 
//    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired (8ma max)
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_6MA); // Set for max power if desired (8ma max)
 
    si5351_output_enable(SI5351_CLK0, 1);
 
    //si5351_pll_reset(SI5351_PLLA);
 

	
 
    // Make sure the other outputs of the SI5351 are disabled
 
    si5351_output_enable(SI5351_CLK1, 0); // Disable the clock initially
 
    si5351_output_enable(SI5351_CLK2, 0); // Disable the clock initially
 

	
 
    // disable clock powers
 
    si5351_set_clock_pwr(SI5351_CLK1, 0);
 
    si5351_set_clock_pwr(SI5351_CLK2, 0);
 

	
0 comments (0 inline, 0 general)