Changeset - 89dc4e02c836
[Not reviewed]
default
0 2 0
Ethan Zonca - 10 years ago 2014-11-22 16:30:15
ez@ethanzonca.com
Sketchy remainder fixing for fahrenheit support
2 files changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
@@ -82,13 +82,13 @@ CDEFS+=-DSTM32L1XX
 
CDEFS+=-DMANGUSTA_DISCOVERY
 
#CDEFS+=-DUSE_USB_OTG_FS
 
CDEFS+=-DHSE_VALUE=8000000
 

	
 

	
 
#EMZ Optimized: 
 
MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections 
 
MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -mfloat-abi=soft
 

	
 
# Default:  MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections
 

	
 
#MCUFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpa -mfloat-abi=hard -mthumb-interwork
 
#MCUFLAGS=-mcpu=cortex-m4 -mfpu=vfpv4-sp-d16 -mfloat-abi=hard
 
COMMONFLAGS=-O$(OPTLVL) -g -Wall
main.c
Show inline comments
 
@@ -139,13 +139,13 @@ int main(void)
 
        // Run state machine
 
        machine(); 
 
    }
 
}
 
 
// Read temperature and update global temp vars
 
int16_t temp = 0;
 
int32_t temp = 0;
 
uint8_t temp_frac = 0;
 
 
void update_temp() {
 
    // Assert CS
 
    GPIO_ResetBits(MAX_CS);
 
    delay(1);
 
@@ -178,16 +178,21 @@ void update_temp() {
 
        }
 
        else {
 
            temp = temp_pre;
 
        }
 
 
        if(temp_units == TEMP_UNITS_FAHRENHEIT) {
 
            temp *= 10; // fixed point mul by 1.8
 
            temp *= 18;
 
            temp /= 100;
 
            temp *= 9; // fixed point mul by 1.8
 
            temp /= 5;
 
            temp += 32;
 
 
            temp_frac *= 9;
 
            temp_frac /= 5;
 
            temp_frac += 32;
 
            temp += temp_frac/100; // add overflow to above
 
            temp_frac %= 100;
 
        }
 
    }
 
 
    // Deassert CS
 
    delay(1);
 
    GPIO_SetBits(MAX_CS);
0 comments (0 inline, 0 general)