Changeset - f228963e487a
[Not reviewed]
default
0 1 0
Ethan Zonca - 10 years ago 2014-08-23 22:29:44
ez@ethanzonca.com
Get fractional part
1 file changed with 1 insertions and 46 deletions:
main.c
1
46
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -46,19 +46,12 @@ char* itoa(int16_t i, char b[]){
 
        *--p = digit[i%10];
 
        i = i/10;
 
    }while(i);
 
    return b;
 
}
 
 
 
int32_t round(double x) {
 
    if (x >= 0)
 
        return (long) (x+0.5);
 
    return (long) (x-0.5);
 
}
 
 
static __IO uint32_t TimingDelay;
 
 
// Move to header file
 
void init_gpio();
 
void init_spi();
 
void process();
 
@@ -183,68 +176,30 @@ void process()
 
        temp = -temp_pre;
 
    }
 
    else {
 
        temp = temp_pre;
 
    }
 
 
 
    // Deassert CS
 
    Delay(1);
 
    GPIO_SetBits(MAX_CS);
 
 
 
    //////////////////////////
 
    // Calc internal temp   //
 
    //////////////////////////
 
/*    temp = temp >> 4; // Drop last 4 bits, no need for them
 
    float internal_temp = temp & 0x7FF // Lower 11bits are internal temp
 
    
 
    // Check internal temp sign
 
    if(temp & 0x800) {
 
        // Convert to negative value by extending sign and casting to signed type.
 
        int16_t tmp = 0xF800 | (temp & 0x7FF);
 
        internal_temp = tmp;
 
    }
 
    internal_temp *= 0.0625; // LSB = 0.0625 degrees
 
    // Now we have a good internal temp!
 
*/
 
    //////////////////////////
 
    // Calc external temp   //
 
    //////////////////////////
 
 
    if(temp > 0) {
 
        GPIO_SetBits(LED_STAT);
 
    }
 
    char tempstr[9];
 
    itoa(temp_pre, tempstr);
 
    ssd1306_DrawString("Temp: ", 1, 40);
 
    ssd1306_DrawString("    ", 1, 70);
 
    ssd1306_DrawString(tempstr, 1, 70);
 
    itoa(frac, tempstr);
 
    ssd1306_DrawString("  ", 1, 90);
 
    ssd1306_DrawString(tempstr, 1, 90);
 
 
/*
 
    if((!retval || (temp & 0x2) != 0))
 
    {
 
        ssd1306_DrawString("!TempCOMMS", 3, 35);
 
        //return; // Comms error - this is happening right now
 
    }
 
 
    else if((temp & 0x4)!= 0)
 
    {
 
        ssd1306_DrawString("!OpenThermocouple", 3, 40);
 
        //return; // Open thermocouple
 
    }
 
 
    temp = (temp & 0x7FF8) >> 5;
 
*/
 
 
    // TODO: Add calibration offset (linear)
 
 
 
    // Perform PID calculations
 
 
    // Write output to SSR
 
}
 
 
 
@@ -474,13 +429,13 @@ void init_spi(void)
 
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
 
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
 
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; // Andysworkshop
 
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // From andysworkshop
 
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // same
 
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
 
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
 
    SPI_InitStructure.SPI_CRCPolynomial = 7;
 
    SPI_Init(SPI2, &SPI_InitStructure);
 
    SPI_Cmd(SPI2, ENABLE);           /* Enable the SPI */
 
}
 
0 comments (0 inline, 0 general)