Jump to content
43oh

fatihinanc

Members
  • Content Count

    56
  • Joined

  • Last visited

  • Days Won

    2

Reputation Activity

  1. Like
    fatihinanc reacted to Lode in G2553 I2C SCL/INT combined?   
    @@fatihinanc
    eUSCI, what mcu are you on exactly?
    Could be handy for the future.
     
    And what scope is that? digital only one?
     
     
    Furthermore
    I don't see your "Calculation of the magnetic flux" as described in the User manual chapter 3, page 9?
     
    This is what I got for that:
    signed int TLV493D_flux12Bit(unsigned int r){     signed int c = 0;                                       //bit value     c -= (r & 0x0800) ? 0x0800 : 0;   //12 ~ 2048     c += (r & 0x0400) ? 0x0400 : 0;   //11 ~ 1024     c += (r & 0x0200) ? 0x0200 : 0;   //10 ~  512     c += (r & 0x0100) ? 0x0100 : 0;   // 9 ~  256     c += (r & 0x0080) ? 0x0080 : 0;   // 8 ~  128     c += (r & 0x0040) ? 0x0040 : 0;   // 7 ~   64     c += (r & 0x0020) ? 0x0020 : 0;   // 6 ~   32     c += (r & 0x0010) ? 0x0010 : 0;   // 5 ~   16     c += (r & 0x0008) ? 0x0008 : 0;   // 4 ~    8     c += (r & 0x0004) ? 0x0004 : 0;   // 3 ~    4     c += (r & 0x0002) ? 0x0002 : 0;   // 2 ~    2     c += (r & 0x0001) ? 0x0001 : 0;   // 1 ~    1     return c; } signed int TLV493D_flux8Bit(unsigned int r){     signed int c = 0;                                       //bit value     c -= (r & 0x0800) ? 0x80 : 0;     //12 ~  128     c += (r & 0x0400) ? 0x40 : 0;     //11 ~   64     c += (r & 0x0200) ? 0x20 : 0;     //10 ~   32     c += (r & 0x0100) ? 0x10 : 0;     // 9 ~   16     c += (r & 0x0080) ? 0x08 : 0;     // 8 ~    8     c += (r & 0x0040) ? 0x04 : 0;     // 7 ~    4     c += (r & 0x0020) ? 0x02 : 0;     // 6 ~    2     c += (r & 0x0010) ? 0x01 : 0;     // 5 ~    1     return c; } unsigned int  x=0, y=0, z=0;         //later in loop....         x = (r[0] << 4) | ((r[4] >> 4) & 0x0F);      // byte 0 + high nibble 4         y = (r[1] << 4) | (r[4] & 0x0F);                // byte 1 + low nibble 4         z = (r[2] << 4) | (r[5] & 0x0F);                // byte 2 + low nibble 5         printf("FRM: %d \n\r", ((r[3] & 0x0C) >> 2));   // frame count         printf("CH:  %d \n\r",  (r[3] & 0x03));         // channel 0=none or x, 1=y, 2=z, 3=temp         printf("PD:  %d \n\r", ((r[5] & 0x10) >> 4));   // power down         printf("x: %d / %d \n\r", TLV493D_flux12Bit(x), TLV493D_flux8Bit(x));         printf("y: %d / %d \n\r", TLV493D_flux12Bit(y), TLV493D_flux8Bit(y));         printf("z: %d / %d \n\r", TLV493D_flux12Bit(z), TLV493D_flux8Bit(z)); FRM should increment 0,1,2,3, 0, etc.
    CH should be zero meaning measurement is finalized.
  2. Like
    fatihinanc reacted to spirilis in GoodFET   
    Why?  Just get a modern LaunchPad and use the eZ-FET Lite on board.
  3. Like
    fatihinanc reacted to KatiePier in Configuring the f5529lp to run at 25 MHz   
    Hi @@nickn,
     
    Looks like you are using driverlib function calls - great! It is recommended to use the PMM_setVCore() function call from driverlib for setting the Vcore level before you change the clock - this has the most recent implementation of what @@fatihinanc showed you in their code. This will do all the single stepping of the core and required checks for you.
     
    For using the UCS functions you mentioned - are you using CCS? If you have CCSv6 with MSP430ware, go to View > Resource Explorer and you can see in MSP430ware under Libraries there is Driver Library, and there should be examples here for all the different driver library functions. I remember there is even one specifically for setting the DCO to a desired frequency on F5xx: in Resource Explorer, MSP430ware > Libraries > Driver Library > MSP430F5xx_6xx > Example Projects > UCS > ucs_ex1_DCO12MHz.
     
    If you have questions about how a particular driverlib function call works, you can find documentation built into Resource Explorer under MSP430ware > Libraries > Driver Library > MSP430F5xx_6xx > API Programmer's Guide. This is html-based documentation - you can click Modules to get a list of all the modules in the device family, click on one of them (like ucs) and it will give you a list of all the function calls for that module. Click on a function call, like UCS_initFLLSettle, and it has a full description and a list of all the parameters that you pass to it.
     
    MSP430ware also has some blank driverlib projects that you can use as a starting place. Let me know if you have any more driverlib questions! I like to help people out with these libraries.
     
    Regards,
    Katie
  4. Like
    fatihinanc got a reaction from nickn in Configuring the f5529lp to run at 25 MHz   
    @@nickn
     
    You just need to set PMM registers and change the core voltage step by step. The code which given below sets the core voltage to correct value and also generates 25 MHz from LFXT1(32.768kHz). It is referenced from TI code examples.(MSP430F55xx_UCS_10.c) Only difference is ACLK = LFXT1, not REFO.
    void set25mhz(void) { P5SEL |= BIT4 + BIT5; // Select XT1 // Increase Vcore setting to level3 to support fsystem=25MHz // NOTE: Change core voltage one level at a time.. SetVcoreUp (0x01); SetVcoreUp (0x02); SetVcoreUp (0x03); UCSCTL6 &= ~(XT1OFF); // XT1 On UCSCTL4 |= SELA_0; // ACLK = LFTX1 (by default) UCSCTL6 |= XCAP_3; // Internal load cap __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operation UCSCTL2 = FLLD_0 | 762; // Set DCO Multiplier for 25MHz // (N + 1) * FLLRef = Fdco // (762 + 1) * 32768 = 25MHz // Set FLL Div = fDCOCLK/2 __bic_SR_register(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle __delay_cycles(782000); // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags }while (SFRIFG1&OFIFG); // Test oscillator fault flag UCSCTL6 &= ~(XT1DRIVE_3); // Xtal is now stable, reduce drive strength } void SetVcoreUp (unsigned int level) { // Open PMM registers for write PMMCTL0_H = PMMPW_H; // Set SVS/SVM high side new level SVSMHCTL = SVSHE | SVSHRVL0 * level | SVMHE | SVSMHRRL0 * level; // Set SVM low side to new level SVSMLCTL = SVSLE | SVMLE | SVSMLRRL0 * level; // Wait till SVM is settled while ((PMMIFG & SVSMLDLYIFG) == 0); // Clear already set flags PMMIFG &= ~(SVMLVLRIFG | SVMLIFG); // Set VCore to new level PMMCTL0_L = PMMCOREV0 * level; // Wait till new level reached if ((PMMIFG & SVMLIFG)) while ((PMMIFG & SVMLVLRIFG) == 0); // Set SVS/SVM low side to new level SVSMLCTL = SVSLE | SVSLRVL0 * level | SVMLE | SVSMLRRL0 * level; // Lock PMM registers for write access PMMCTL0_H = 0x00; }
  5. Like
    fatihinanc got a reaction from oPossum in Configuring the f5529lp to run at 25 MHz   
    @@nickn
     
    You just need to set PMM registers and change the core voltage step by step. The code which given below sets the core voltage to correct value and also generates 25 MHz from LFXT1(32.768kHz). It is referenced from TI code examples.(MSP430F55xx_UCS_10.c) Only difference is ACLK = LFXT1, not REFO.
    void set25mhz(void) { P5SEL |= BIT4 + BIT5; // Select XT1 // Increase Vcore setting to level3 to support fsystem=25MHz // NOTE: Change core voltage one level at a time.. SetVcoreUp (0x01); SetVcoreUp (0x02); SetVcoreUp (0x03); UCSCTL6 &= ~(XT1OFF); // XT1 On UCSCTL4 |= SELA_0; // ACLK = LFTX1 (by default) UCSCTL6 |= XCAP_3; // Internal load cap __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operation UCSCTL2 = FLLD_0 | 762; // Set DCO Multiplier for 25MHz // (N + 1) * FLLRef = Fdco // (762 + 1) * 32768 = 25MHz // Set FLL Div = fDCOCLK/2 __bic_SR_register(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle __delay_cycles(782000); // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags }while (SFRIFG1&OFIFG); // Test oscillator fault flag UCSCTL6 &= ~(XT1DRIVE_3); // Xtal is now stable, reduce drive strength } void SetVcoreUp (unsigned int level) { // Open PMM registers for write PMMCTL0_H = PMMPW_H; // Set SVS/SVM high side new level SVSMHCTL = SVSHE | SVSHRVL0 * level | SVMHE | SVSMHRRL0 * level; // Set SVM low side to new level SVSMLCTL = SVSLE | SVMLE | SVSMLRRL0 * level; // Wait till SVM is settled while ((PMMIFG & SVSMLDLYIFG) == 0); // Clear already set flags PMMIFG &= ~(SVMLVLRIFG | SVMLIFG); // Set VCore to new level PMMCTL0_L = PMMCOREV0 * level; // Wait till new level reached if ((PMMIFG & SVMLIFG)) while ((PMMIFG & SVMLVLRIFG) == 0); // Set SVS/SVM low side to new level SVSMLCTL = SVSLE | SVSLRVL0 * level | SVMLE | SVSMLRRL0 * level; // Lock PMM registers for write access PMMCTL0_H = 0x00; }
  6. Like
    fatihinanc got a reaction from bluehash in Configuring the f5529lp to run at 25 MHz   
    @@nickn
     
    You just need to set PMM registers and change the core voltage step by step. The code which given below sets the core voltage to correct value and also generates 25 MHz from LFXT1(32.768kHz). It is referenced from TI code examples.(MSP430F55xx_UCS_10.c) Only difference is ACLK = LFXT1, not REFO.
    void set25mhz(void) { P5SEL |= BIT4 + BIT5; // Select XT1 // Increase Vcore setting to level3 to support fsystem=25MHz // NOTE: Change core voltage one level at a time.. SetVcoreUp (0x01); SetVcoreUp (0x02); SetVcoreUp (0x03); UCSCTL6 &= ~(XT1OFF); // XT1 On UCSCTL4 |= SELA_0; // ACLK = LFTX1 (by default) UCSCTL6 |= XCAP_3; // Internal load cap __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operation UCSCTL2 = FLLD_0 | 762; // Set DCO Multiplier for 25MHz // (N + 1) * FLLRef = Fdco // (762 + 1) * 32768 = 25MHz // Set FLL Div = fDCOCLK/2 __bic_SR_register(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle __delay_cycles(782000); // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags }while (SFRIFG1&OFIFG); // Test oscillator fault flag UCSCTL6 &= ~(XT1DRIVE_3); // Xtal is now stable, reduce drive strength } void SetVcoreUp (unsigned int level) { // Open PMM registers for write PMMCTL0_H = PMMPW_H; // Set SVS/SVM high side new level SVSMHCTL = SVSHE | SVSHRVL0 * level | SVMHE | SVSMHRRL0 * level; // Set SVM low side to new level SVSMLCTL = SVSLE | SVMLE | SVSMLRRL0 * level; // Wait till SVM is settled while ((PMMIFG & SVSMLDLYIFG) == 0); // Clear already set flags PMMIFG &= ~(SVMLVLRIFG | SVMLIFG); // Set VCore to new level PMMCTL0_L = PMMCOREV0 * level; // Wait till new level reached if ((PMMIFG & SVMLIFG)) while ((PMMIFG & SVMLVLRIFG) == 0); // Set SVS/SVM low side to new level SVSMLCTL = SVSLE | SVSLRVL0 * level | SVMLE | SVSMLRRL0 * level; // Lock PMM registers for write access PMMCTL0_H = 0x00; }
  7. Like
    fatihinanc got a reaction from bluehash in 43oh Welcomes Stellarisiti, BeagleFu and C2000 Members   
    Hi bluehash,
     
    Good to see you've merged all forums together. 43oh will be more enjoyable place then before.
  8. Like
    fatihinanc got a reaction from greeeg in New Launchpad just dropped   
    Hey there,
     
    Is MSP430FR4133 have "CPU" or "CPUXV2" ?
    I didn't found any information about it is CPUXV2 or not.
     
    BTW, I just ordered one. FR4x and FR2x product line is really good for price/performance.
    MSP430FR4133 is only 1.55$ 
  9. Like
    fatihinanc reacted to abecedarian in New Launchpad just dropped   
    Device family guide for FR4xx & FR2xx:
    http://www.ti.com/lit/pdf/slau445 Page 104.
     

  10. Like
    fatihinanc reacted to RobG in CC2500 & Anaren code example   
    This code example works with Anaren and CC2500 BoosterPacks, (and of course with many other CCxxxx boards, like eZ430-RF2500,) and with G2553 LaunchPad.
    The code was based on slaa325 from TI (I am using same RF configs.)
     
    To use it, just un-comment one of the following lines in msp.h:
    //#define HARDWARE 2500 // CC2500 BoosterPack SPI1 G2553 LP //#define HARDWARE 915 // Anaren (915MHz) G2553 LP //#define HARDWARE 4302500 // EZ430-RF2500
     
     
    CCxxxx.zip
  11. Like
    fatihinanc reacted to jpnorair in Code Composer Studio v6 now officially released   
    It's a shame it doesn't support OS X.  You think TI would have figured-out that in the last 5 years, virtually all software devs in the USA have switched to Mac, and this represents a lot of the hobbyist community.  I use a mac for my personal laptop, and if CCS were available to run natively I might muck around with MSP430 on the weekends.  Oh well, maybe v6.1.
  12. Like
    fatihinanc got a reaction from bkb in Simple HD44780 Library without driverlib   
    Hello,
     
    I have tested 2x16 LCD and works well. Included pll and systick routines.
    Thist project is wroted withotut any driverlib functions. It will be a good example for "bare-metal coding".
     
    https://github.com/fatihinanc/stellaris-launchpad/tree/master/1602_lcd
     
    HD44780 1602 LCD Connections;
     
    RS -> PB0
    EN -> PB1
     
    D4 -> PD0
    D5 -> PD1
    D6 -> PD2
    D7 -> PD3
     

     
  13. Like
    fatihinanc reacted to bluehash in Add your Github/Repo link to your profiles   
    Sorry all.. it is now fixed.
  14. Like
    fatihinanc got a reaction from TheDirty1426459890 in Simple HD44780 Library without driverlib   
    Hello,
     
    I have tested 2x16 LCD and works well. Included pll and systick routines.
    Thist project is wroted withotut any driverlib functions. It will be a good example for "bare-metal coding".
     
    https://github.com/fatihinanc/stellaris-launchpad/tree/master/1602_lcd
     
    HD44780 1602 LCD Connections;
     
    RS -> PB0
    EN -> PB1
     
    D4 -> PD0
    D5 -> PD1
    D6 -> PD2
    D7 -> PD3
     

     
  15. Like
    fatihinanc got a reaction from bluehash in Simple HD44780 Library without driverlib   
    Hello,
     
    I have tested 2x16 LCD and works well. Included pll and systick routines.
    Thist project is wroted withotut any driverlib functions. It will be a good example for "bare-metal coding".
     
    https://github.com/fatihinanc/stellaris-launchpad/tree/master/1602_lcd
     
    HD44780 1602 LCD Connections;
     
    RS -> PB0
    EN -> PB1
     
    D4 -> PD0
    D5 -> PD1
    D6 -> PD2
    D7 -> PD3
     

     
  16. Like
    fatihinanc got a reaction from Rickta59 in Any NXP/LPC ARM users here?   
    Cortex M0 architecture is quite easy And possible to making a simple example(UART,SPI,ADC etc.) is simply with libraries of provided by NXP,
  17. Like
    fatihinanc got a reaction from jazz in Launchpad as external programmer   
    I have both of v1.3 and v1.4 version LP's and I have found a wiki page about updating eZ430.
    I've updated my LP's using FET430 UIF and now both of LP's, programing F5x devices too fast.
    And after the programming Flash(Quick Download in IAR, without Debug) the Reset button is works. In the older revision, I have to unplug and plug the LaunchPad for running the downloaded code.
    I strongly recommend it
     
    Specifications of eZ430 Firmware V30394216 Release Date: 11/09/2011
     
    Supported Features:

    LPMx.5 debug support( if device supports this)
    FRAM memory technology support
    FR5739 MPU handling
    FastEasy: fast FLASH and FRAM programming
     
    Supported Devices:

    CC430 Family
    FR573x Family
    5510 Family
    5529 Family
    5172 Family
    5438 Family
    5438A Family
    2GXX Family
    2xx Family
     
    Supported Tools:

    CC430-EXP
    FR5739-EXP
    5529-EXP
    Fossil Watch
    Chronos Watch
    Launchpad
    ez430-2500RF
     
    This is the link : http://processors.wiki.ti.com/index.php/EZ430_Emulator_Upgrade
  18. Like
    fatihinanc reacted to bytesize in STM32 ILI9481 TFT LCD Driver   
    Another good tutorial from Andy Brown... details wiring as well as communication protocol between the STM32 and the ILI9481 display driver.
     



  19. Like
    fatihinanc got a reaction from bytesize in Sourcery CodeBench Lite Edition   
    Yes. This wiki explains how to do this.
    http://processors.wiki.ti.com/index.php/How_to_create_GCC_projects_in_CCSv5
  20. Like
    fatihinanc got a reaction from Rickta59 in Sourcery CodeBench Lite Edition   
    Yes. This wiki explains how to do this.
    http://processors.wiki.ti.com/index.php/How_to_create_GCC_projects_in_CCSv5
  21. Like
    fatihinanc got a reaction from bluehash in Sourcery CodeBench Lite Edition   
    Yes. This wiki explains how to do this.
    http://processors.wiki.ti.com/index.php/How_to_create_GCC_projects_in_CCSv5
  22. Like
    fatihinanc reacted to MattTheGeek in [RFS] MotorPack - 4 CH motor controller booster pack   
    Still need to calculate some resistor values, etc...

  23. Like
    fatihinanc reacted to dkedr in nrf24L01 registers/commands and functions(work in progress)   
    nrf24L01.h Contains command and register address definitions.
    nrf24L01.c Contains functions (tx not tested but should work, rx not tested)
    regs.h Contains settings for the MSP430 and the nrf24L01
    main.c - Demo main program code
     
    Apparently the nrf24L01 can take a pules on CS without any delay. If any one runs into a problem with this do tell.
     
    The delay from PWR_UP being written to CE going high is very crucial. If not observed, the nrf24L01 will not work.
     
    Also by the looks of it the nrf24L01 can take 16Mbps SPI. I don't have a logic analyzer to test this, but my code seams to work.
     
    regs.h hold a definition "test_config". If it's set to "1" a demo type program will run.
    If it's defined as "0" the test code will not be included.
    tx1st defines if the nrf will be in tx mode when it power up. If set to "0" nrf will be in RX mode.
    The code in main.c should increment the RX_ADDR_P0 then send it to the received address.
    If the msp that is transmitting doesn't receive an ACK, it will turn on LED1 and go into LPM4.
    This should continue indefinitely. Only the LSB of the address is changing, and should roll over.
     
     
     
    tx is working now, tested with msp430g2252 on the tx side and the buspirate on the rx side
    rx is still untested. (Will test later)
    regs.h
    nrf24l01.h
    nrf24l01.c
    main.c
    nrf test.buspirate.txt
  24. Like
    fatihinanc got a reaction from GeekDoc in ADC calibration constants   
    Each segment is 64 byte and Segment A is in last quarter.
    Just debug your program and watch the 0x01000 - 0x010FF addresses.
  25. Like
    fatihinanc reacted to oPossum in Using the internal temperature sensor   
    TI has some sample code for the internal temperature sensor, but it does not explain how to scale the ADC reading to useful units of degrees. Here is a step-by-step explanation of how to do the scaling with integer math for degrees C, K and F. There is also sample code to display the temperature on a Nokia 5110 LCD.

     
    The data sheet (SLAU144) has this formula for converting temperature in degrees Celsius to voltage.
    V = 0.00355 * C + 0.986

    What we need is a formula for converting voltage to temperature.
     
    Rewrite the data sheet fomula with temperature on the left
    0.00355 * C + 0.986 = V
     
    Divide both sides by 0.00355
    C + 277.75 = V / 0.00355
     
    Subtract 277.75 from both sides
    C = V / 0.00355 - 277.75
     
    Now we have a formula for converting voltage to temperature.
     
    The data sheet has this formula for converting voltage to ADC value, once again the opposite of what we neeed.

    For Vref- == 0
    A = 1023 * V / Vref
     
    Swap sides
    1023 * V / Vref = A
     
    Multiply by Vref
    1023 * V = A * Vref
     
    Divide by 1023
    V = A * Vref / 1023
     
    For a 1.5V reference
    V = A * 1.5 / 1023
     
    Simplify
    V = A * 0.0014663
     
    Substitute ADC conversion forumula for voltage in the temperature conversion formula.
    C = A * 0.0014663 / 0.00355 - 277.75
     
    Simplify
    C = A * 0.413 - 277.75
     
    Now we have a formula to convert ADC reading to temperature.
    It uses real numbers, so floating point math is required for good precision.
    Floating point is slow and requires more flash, so let's use integer math instead.
    Multiply by 65536 (2^16) and then divide by the same.
    C = (A * 27069 - 18202393) / 65536
     
    Use a right shift instead of divide. This will become a move of high word to low word.
    C = (A * 27069 - 18202393) >> 16
     
    Add 0.5 * 65536 to impove rounding.
    C = (A * 27069 - 18202393 + 32768) >> 16
     
    Simplify.
    C = (A * 27069 - 18169625) >> 16
     
    So that is how to go from ADC to degrees Celsius.
     
     
    To convert degrees C to degees K.
    K = C + 273.15
     
    Applied to ADC to degrees C conversion formula.
    K = (A * 27069 - 18169625) >> 16 - 273.15
     
    Implement with integer math by multiplying by 65536
    K = (A * 27069 - 18169625 - 17,901,158) >> 16
     
    Simplify.
    K = (A * 27069 - 268467) >> 16
     
    To convert degrees C to degrees F.
    F = C * 9 / 5 + 32
     
    Applied to voltage to degrees C conversion forumula
    F = (V / 0.00355 - 277.75) * 9 / 5 + 32
     
    Multiply by 9
    F = (V / 0.0003944 - 2499.75) / 5 + 32
     
    Divide by 5
    F = (V / 0.0019722 - 499.95) + 32
     
    Add 32
    F = V / 0.0019722 - 467.95
     
    Substitute ADC to voltage forumula
    F = A * 0.0014663 / 0.0019722 - 467.95
     
    Simplifiy
    F = A * 0.7435 - 467.95
     
    Convert to integer
    F = (A * 48724 - 30667156) >> 16
     
    Improve rounding
    F = (A * 48724 - 30667156 + 32768) >> 16
     
    Simplify
    F = (A * 48724 - 30634388) >> 16
     
    So now we have three formulas to convert ADC reading to degrees C, K and F using fast and compact integer math.
    C = (A * 27069 - 18169625) >> 16
    K = (A * 27069 - 268467) >> 16
    F = (A * 48724 - 30634388) >> 16
     
    Using the ADC value, rather than a different temperature scale, will ensure greatest precision for each temperature scale.
     
    main.c

    #include #include #include "lcd.h" #define ADC_SLEEP // Sleep during ADC conversion //#define SHOW_ADC // Show ADC raw and ADC millivolts // Print integer from -999 to 9999 using 12 x 16 font void print_int(int i, const unsigned y) { if(i < -999 || i > 9999) return; const unsigned neg = i < 0; if(neg) i = -i; div_t d; d.quot = i; unsigned x = 48; do { d = div(d.quot, 10); pd12(d.rem, x -= 12, y); } while(d.quot); if(neg) pd12(14, x -= 12, y); while(x) pd12(10, x -= 12, y); } // Print integer from 0 to 9999 vertically using 6 x 8 font void print_v(int i, unsigned x) { unsigned y = 4; unsigned c; if(i < 0 || i > 9999) return; div_t d; d.quot = i; do { d = div(d.quot, 10); c = d.rem + '0'; lcd_print((char *)&c, x, --y); } while(d.quot); c = ' '; while(y) lcd_print((char *)&c, x, --y); } void main(void) { unsigned adc; // ADC value int c, k, f; // Temperature in degrees C, K, and F unsigned mv; // ADC reading in millivolts // WDTCTL = WDTPW | WDTHOLD; // Disable watchdog reset // lcd_init(); // Initialize LCD lcd_clear(0); // pd12(15, 48, 0); // Degrees pd12(17, 59, 0); // F pd12(15, 48, 2); // Degrees pd12(16, 58, 2); // C pd12(15, 48, 4); // Degrees pd12(18, 59, 4); // K #ifdef SHOW_ADC // lcd_print("Am", 72, 4); // AD / mV lcd_print("DV", 72, 5); // #endif // // ADC10CTL0 = 0; // Configure ADC ADC10CTL1 = INCH_10 | ADC10DIV_3; // ADC10CTL0 = SREF_1 | ADC10SHT_3 | REFON | ADC10ON | ADC10IE; //ADC10CTL0 = SREF_1 | ADC10SHT_3 | REFON | ADC10ON | ADC10IE | REF2_5V; #ifdef ADC_SLEEP // ADC10CTL0 |= ADC10IE; // Enable ADC conversion complete interrupt #endif // // for(; { // for-ever #ifdef ADC_SLEEP // ADC10CTL0 |= (ENC | ADC10SC); // Begin ADC conversion __bis_SR_register(LPM0_bits + GIE); // Sleep until conversion complete #else // ADC10CTL0 &= ~ADC10IFG; // Clear conversion complete flag ADC10CTL0 |= (ENC | ADC10SC); // Begin ADC conversion while(!(ADC10CTL0 & ADC10IFG)); // Wait for conversion to complete #endif // // adc = ADC10MEM; // Read ADC // // Convert to temperature c = ((27069L * adc) - 18169625L) >> 16; // Vref = 1.5V //c = ((45115L * adc) - 18169625L) >> 16; // Vref = 2.5V // k = ((27069L * adc) - 268467L) >> 16; // Vref = 1.5V //k = ((45115L * adc) - 268467L) >> 16; // Vref = 2.5V // f = ((48724L * adc) - 30634388L) >> 16; // Vref = 1.5V //f = ((81206L * adc) - 30634388L) >> 16; // Vref = 2.5V // // Convert to millivolts mv = (96094L * adc + 32768) >> 16; // Vref = 1.5V //mv = (160156L * adc + 32768) >> 16; // Vref = 2.5V // // Display on LCD print_int(f, 0); // Degrees F print_int(c, 2); // Degrees C print_int(k, 4); // Degrees K // #ifdef SHOW_ADC // print_v(adc, 72); // ADC print_v(mv, 78); // ADC millivolts #endif // // //__delay_cycles(100000); // } // } #pragma vector = ADC10_VECTOR // ADC conversion complete interrupt __interrupt void ADC10_ISR(void) // { // __bic_SR_register_on_exit(LPM0_bits); // Wakeup main code } //
     
    lcd.h

    typedef enum { lcd_command = 0, // Array of one or more commands lcd_data = 1, // Array of one or more bytes of data lcd_data_repeat = 2 // One byte of data repeated } lcd_cmd_type; void lcd_send(const unsigned char *cmd, unsigned len, const lcd_cmd_type type); void lcd_home(void); void lcd_pos(unsigned char x, unsigned char y); void lcd_clear(unsigned char x); void lcd_init(void); void lcd_print(char *s, unsigned x, unsigned y); void pd12(unsigned n, unsigned x, unsigned y);
     
    lcd.c

    #include #include "lcd.h" //static const unsigned TXD = BIT1; static const unsigned RXD = BIT2; static const unsigned SWITCH = BIT3; static const unsigned LCD_CLK = BIT5; static const unsigned LCD_BACKLIGHT = BIT6; static const unsigned LCD_DATA = BIT7; static const unsigned LCD_DC = BIT0; // PORT2 static const unsigned LCD_CE = BIT1; // PORT2 void lcd_send(const unsigned char *cmd, unsigned len, const lcd_cmd_type type) { register unsigned mask; P2OUT &= ~LCD_CE; do { mask = 0x0080; do { if(*cmd & mask) { P1OUT &= ~LCD_CLK; P1OUT |= LCD_DATA; } else { P1OUT &= ~(LCD_CLK | LCD_DATA); } P1OUT |= LCD_CLK; mask >>= 1; } while(!(mask & 1)); if(!type) P2OUT &= ~LCD_DC; if(*cmd & mask) { P1OUT &= ~LCD_CLK; P1OUT |= LCD_DATA; } else { P1OUT &= ~(LCD_CLK | LCD_DATA); } P1OUT |= LCD_CLK; P2OUT |= LCD_DC; if(!(type & 2)) ++cmd; } while(--len); P2OUT |= LCD_CE; } static const unsigned char home[] = { 0x40, 0x80 }; void lcd_home(void) { lcd_send(home, sizeof(home), lcd_command); } void lcd_pos(unsigned char x, unsigned char y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 | y; lcd_send(c, sizeof(c), lcd_command); } void lcd_clear(unsigned char x) { lcd_home(); lcd_send(&x, 504, lcd_data_repeat); lcd_home(); } void lcd_init(void) { static const unsigned char init[] = { 0x20 + 0x01, // function set - extended instructions enabled //0x80 + 64, // set vop (contrast) 0 - 127 0x80 + 66, // set vop (contrast) 0 - 127 0x04 + 0x02, // temperature control 0x10 + 0x03, // set bias system 0x20 + 0x00, // function set - chip active, horizontal addressing, basic instructions 0x08 + 0x04 // display control - normal mode }; P1REN = RXD | SWITCH; P1DIR = LCD_CLK | LCD_BACKLIGHT | LCD_DATA; P1OUT = LCD_CLK | RXD | SWITCH | LCD_BACKLIGHT; P2REN = 0; P2DIR = LCD_DC | LCD_CE; P2OUT = LCD_CE; __delay_cycles(20000); P2OUT |= LCD_DC; __delay_cycles(20000); lcd_send(init, sizeof(init), lcd_command); } static const unsigned char font6x8[96][5] = { 0x00, 0x00, 0x00, 0x00, 0x00, // 20 32 0x00, 0x00, 0x5F, 0x00, 0x00, // 21 33 ! 0x00, 0x07, 0x00, 0x07, 0x00, // 22 34 " 0x14, 0x7F, 0x14, 0x7F, 0x14, // 23 35 # 0x24, 0x2A, 0x7F, 0x2A, 0x12, // 24 36 $ 0x23, 0x13, 0x08, 0x64, 0x62, // 25 37 % 0x36, 0x49, 0x56, 0x20, 0x50, // 26 38 & 0x00, 0x08, 0x07, 0x03, 0x00, // 27 39 ' 0x00, 0x1C, 0x22, 0x41, 0x00, // 28 40 ( 0x00, 0x41, 0x22, 0x1C, 0x00, // 29 41 ) 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // 2A 42 * 0x08, 0x08, 0x3E, 0x08, 0x08, // 2B 43 + 0x00, 0x40, 0x38, 0x18, 0x00, // 2C 44 , 0x08, 0x08, 0x08, 0x08, 0x08, // 2D 45 - 0x00, 0x00, 0x60, 0x60, 0x00, // 2E 46 . 0x20, 0x10, 0x08, 0x04, 0x02, // 2F 47 / 0x3E, 0x51, 0x49, 0x45, 0x3E, // 30 48 0 0x00, 0x42, 0x7F, 0x40, 0x00, // 31 49 1 0x42, 0x61, 0x51, 0x49, 0x46, // 32 50 2 0x21, 0x41, 0x49, 0x4D, 0x33, // 33 51 3 0x18, 0x14, 0x12, 0x7F, 0x10, // 34 52 4 0x27, 0x45, 0x45, 0x45, 0x39, // 35 53 5 0x3C, 0x4A, 0x49, 0x49, 0x30, // 36 54 6 0x41, 0x21, 0x11, 0x09, 0x07, // 37 55 7 0x36, 0x49, 0x49, 0x49, 0x36, // 38 56 8 0x06, 0x49, 0x49, 0x29, 0x1E, // 39 57 9 0x00, 0x00, 0x14, 0x00, 0x00, // 3A 58 : 0x00, 0x00, 0x40, 0x34, 0x00, // 3B 59 ; 0x00, 0x08, 0x14, 0x22, 0x41, // 3C 60 < 0x14, 0x14, 0x14, 0x14, 0x14, // 3D 61 = 0x00, 0x41, 0x22, 0x14, 0x08, // 3E 62 > 0x02, 0x01, 0x51, 0x09, 0x06, // 3F 63 ? 0x3E, 0x41, 0x5D, 0x59, 0x4E, // 40 64 @ 0x7C, 0x12, 0x11, 0x12, 0x7C, // 41 65 A 0x7F, 0x49, 0x49, 0x49, 0x36, // 42 66 B 0x3E, 0x41, 0x41, 0x41, 0x22, // 43 67 C 0x7F, 0x41, 0x41, 0x41, 0x3E, // 44 68 D 0x7F, 0x49, 0x49, 0x49, 0x41, // 45 69 E 0x7F, 0x09, 0x09, 0x09, 0x01, // 46 70 F 0x3E, 0x41, 0x49, 0x49, 0x7A, // 47 71 G 0x7F, 0x08, 0x08, 0x08, 0x7F, // 48 72 H 0x00, 0x41, 0x7F, 0x41, 0x00, // 49 73 I 0x20, 0x40, 0x41, 0x3F, 0x01, // 4A 74 J 0x7F, 0x08, 0x14, 0x22, 0x41, // 4B 75 K 0x7F, 0x40, 0x40, 0x40, 0x40, // 4C 76 L 0x7F, 0x02, 0x1C, 0x02, 0x7F, // 4D 77 M 0x7F, 0x04, 0x08, 0x10, 0x7F, // 4E 78 N 0x3E, 0x41, 0x41, 0x41, 0x3E, // 4F 79 O 0x7F, 0x09, 0x09, 0x09, 0x06, // 50 80 P 0x3E, 0x41, 0x51, 0x21, 0x5E, // 51 81 Q 0x7F, 0x09, 0x19, 0x29, 0x46, // 52 82 R 0x26, 0x49, 0x49, 0x49, 0x32, // 53 83 S 0x01, 0x01, 0x7F, 0x01, 0x01, // 54 84 T 0x3F, 0x40, 0x40, 0x40, 0x3F, // 55 85 U 0x1F, 0x20, 0x40, 0x20, 0x1F, // 56 86 V 0x3F, 0x40, 0x38, 0x40, 0x3F, // 57 87 W 0x63, 0x14, 0x08, 0x14, 0x63, // 58 88 X 0x03, 0x04, 0x78, 0x04, 0x03, // 59 89 Y 0x61, 0x51, 0x49, 0x45, 0x43, // 5A 90 Z 0x00, 0x7F, 0x41, 0x41, 0x41, // 5B 91 [ 0x02, 0x04, 0x08, 0x10, 0x20, // 5C 92 '\' 0x00, 0x41, 0x41, 0x41, 0x7F, // 5D 93 ] 0x04, 0x02, 0x01, 0x02, 0x04, // 5E 94 ^ 0x80, 0x80, 0x80, 0x80, 0x80, // 5F 95 _ 0x00, 0x03, 0x07, 0x08, 0x00, // 60 96 ' 0x20, 0x54, 0x54, 0x54, 0x78, // 61 97 a 0x7F, 0x28, 0x44, 0x44, 0x38, // 62 98 b 0x38, 0x44, 0x44, 0x44, 0x28, // 63 99 c 0x38, 0x44, 0x44, 0x28, 0x7F, // 64 100 d 0x38, 0x54, 0x54, 0x54, 0x18, // 65 101 e 0x00, 0x08, 0x7E, 0x09, 0x02, // 66 102 f 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // 67 103 g 0x7F, 0x08, 0x04, 0x04, 0x78, // 68 104 h 0x00, 0x44, 0x7D, 0x40, 0x00, // 69 105 i 0x00, 0x20, 0x40, 0x40, 0x3D, // 6A 106 j 0x00, 0x7F, 0x10, 0x28, 0x44, // 6B 107 k 0x00, 0x41, 0x7F, 0x40, 0x00, // 6C 108 l 0x7C, 0x04, 0x78, 0x04, 0x78, // 6D 109 m 0x7C, 0x08, 0x04, 0x04, 0x78, // 6E 110 n 0x38, 0x44, 0x44, 0x44, 0x38, // 6F 111 o 0xFC, 0x18, 0x24, 0x24, 0x18, // 70 112 p 0x18, 0x24, 0x24, 0x18, 0xFC, // 71 113 q 0x7C, 0x08, 0x04, 0x04, 0x08, // 72 114 r 0x48, 0x54, 0x54, 0x54, 0x24, // 73 115 s 0x04, 0x04, 0x3F, 0x44, 0x24, // 74 116 t 0x3C, 0x40, 0x40, 0x20, 0x7C, // 75 117 u 0x1C, 0x20, 0x40, 0x20, 0x1C, // 76 118 v 0x3C, 0x40, 0x30, 0x40, 0x3C, // 77 119 w 0x44, 0x28, 0x10, 0x28, 0x44, // 78 120 x 0x4C, 0x90, 0x90, 0x90, 0x7C, // 79 121 y 0x44, 0x64, 0x54, 0x4C, 0x44, // 7A 122 z 0x00, 0x08, 0x36, 0x41, 0x00, // 7B 123 { 0x00, 0x00, 0x77, 0x00, 0x00, // 7C 124 | 0x00, 0x41, 0x36, 0x08, 0x00, // 7D 125 } 0x02, 0x01, 0x02, 0x04, 0x02, // 7E 126 ~ 0x00, 0x06, 0x09, 0x09, 0x06, // 7F 127 degrees }; void lcd_print(char *s, unsigned x, unsigned y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 | y; lcd_send(c, sizeof(c), lcd_command); while(*s) { lcd_send(&font6x8[*s - 32][0], 5, lcd_data); lcd_send(&font6x8[0][0], 1, lcd_data); ++s; } } static const unsigned char num11x16[19][11 * 2] = { 0x00,0xF0,0xFC,0xFE,0x06,0x02,0x06,0xFE,0xFC,0xF0,0x00, // 0 0x00,0x07,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x07,0x00, 0x00,0x00,0x08,0x0C,0xFC,0xFE,0xFE,0x00,0x00,0x00,0x00, // 1 0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x00, 0x00,0x0C,0x0E,0x06,0x02,0x02,0x86,0xFE,0x7C,0x38,0x00, // 2 0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x38,0x00, 0x00,0x0C,0x0E,0x86,0x82,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 3 0x00,0x18,0x38,0x30,0x20,0x20,0x31,0x3F,0x1F,0x0E,0x00, 0x00,0x00,0xC0,0x20,0x18,0x04,0xFE,0xFE,0xFE,0x00,0x00, // 4 0x00,0x03,0x02,0x02,0x02,0x22,0x3F,0x3F,0x3F,0x22,0x02, 0x00,0x00,0x7E,0x7E,0x46,0x46,0xC6,0xC6,0x86,0x00,0x00, // 5 0x00,0x18,0x38,0x30,0x20,0x20,0x30,0x3F,0x1F,0x0F,0x00, 0x00,0xC0,0xF0,0xF8,0xFC,0x4C,0xC6,0xC2,0x82,0x00,0x00, // 6 0x00,0x0F,0x1F,0x3F,0x30,0x20,0x30,0x3F,0x1F,0x0F,0x00, 0x00,0x06,0x06,0x06,0x06,0x06,0xC6,0xF6,0x3E,0x0E,0x00, // 7 0x00,0x00,0x00,0x30,0x3C,0x0F,0x03,0x00,0x00,0x00,0x00, 0x00,0x38,0x7C,0xFE,0xC6,0x82,0xC6,0xFE,0x7C,0x38,0x00, // 8 0x00,0x0E,0x1F,0x3F,0x31,0x20,0x31,0x3F,0x1F,0x0E,0x00, 0x00,0x78,0xFC,0xFE,0x86,0x02,0x86,0xFE,0xFC,0xF8,0x00, // 9 0x00,0x00,0x00,0x21,0x21,0x31,0x1D,0x1F,0x0F,0x03,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x70,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // : 0x00,0x0E,0x0E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // . 0x00,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC0,0x30,0x0C,0x00,0x00,0x00,0x00, // / 0x00,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, // - 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x00,0x18,0x3C,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00, // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x0E,0x0C,0x00, // C 0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x1C,0x0C,0x00, 0xFE,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x00,0x00,0x00, // F 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFE,0xFE,0x40,0xE0,0xB0,0x18,0x0C,0x06,0x02,0x00,0x00, // K 0x1F,0x1F,0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x10,0x00 }; void pd12(unsigned n, unsigned x, unsigned y) { unsigned char c[2]; c[0] = 0x80 | x; c[1] = 0x40 + y; lcd_send(c, 2, lcd_command); lcd_send(num11x16[n], 11, lcd_data); c[1] = 0x41 + y; lcd_send(c, 2, lcd_command); lcd_send(num11x16[n] + 11, 11, lcd_data); }
×
×
  • Create New...