Jump to content


  • Content Count

  • Joined

  • Last visited

About B.Noll

  • Rank
    Noob Class

Profile Information

  • Gender

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. #include "inc/lm4f120h5qr.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" #include <inttypes.h> // ---- PORTF Launchpad 5x GPIOs (PF0 - PF4) ---- /* PORTF PIN Default Func. Connect@ Description PF0 28 NMI PIN0 SW2 Non-Maskable Interrupt PF1 29 GPIO PIN1 RGB LED (Red) By Default standard GPIO PF2 30 GPIO PIN2 RGB LED (Blue) "" PF3 31 GPIO PIN3 RGD LED (Green) "" PF4 5 GPIO PIN4 SW1 "" */ __no_init volatile union { uint8_t PORTFOUT; struct { uint8_t P0:1, P1:1, P2:1, P3:1, P4:1, P5:1, P6:1, P7:1; } PORTFOUT_BIT; } @0x400253FC; // GPIO_PORTF_DATA_R Base Address, see lm4f120h5qr.h for more details. #define LED_RED PORTFOUT_BIT.P1 #define LED_BLUE PORTFOUT_BIT.P2 #define LED_GREEN PORTFOUT_BIT.P3 void main (void) { SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // Enable PORTF GPIO GPIO_PORTF_DIR_R = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3; // LED Pins as Outputs GPIO_PORTF_DEN_R = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3; // PORTF LED Pins Digital ENable PORTFOUT = 0; // Clear PORTF for (; { LED_BLUE ^= 1; // toggle blue LED SysCtlDelay (1000000); } } Try out the BIT Macro that I have created. You can give each PIN an individual Name and the C Code becomes more readable.
  2. There is no need to use these formulas as there is a more simple way to do such conversion. Simply get the ADC Value for 2 exact temperatures like 0 Celsius and 37 Celsius so we can use Ice as a reference and the temperature of our body :-) then make the equation. I have attached a code that I wrote a while ago, find it attached. Sorry that the comments are in German but I guess the code is so simple that you don't need a translation. msp430x2xxTemperatur.c
  3. B.Noll

    ADC10 TestCode

    I agree. If you want to get a precise result then you should use a better ADC. In the given example oversampling does a good job. If you add noise to the input signal then you can get an extra BIT without any problem but If you have a perfect input signal then you are right. The noise is the key point here.
  4. B.Noll

    ADC10 TestCode

    Mh, intersting discussion :-) Ok, let's take a 2 BIT ADC and let's assume a range of 0-4 V. The result we get: ADC Value 0V + | 00 | | 1V + | 01 | | 2V + | 10 | | 3V + | 11 | | 4V + So the ADC will divide the range from 0-4 V in 4 portions, each has a range of 1V. The key point is how many different numbers can be generated by 2 BIT's and that's exactly 4 because 0 is a number as well. Keep in mind that an ADC return value does not stand for a sepcific Voltage, it stands for a range of Volt. If the return value of the ADC is 10 (decimal = 2) then the Voltage is somewhere in the range between 2V - 3V. Where exactly ? we dont know. Let's think about a 10 BIT ADC. This time you will get 4/1024 portions. The range of each portion will become smaller but this does not mean that we have less then 1024. However, the last ADC Value will be 1024-1. So think about it. In respect to the oversampling example you gave I would agree but if you use a 10 BIT ADC and calculate the noise you need to make that oversampling then I can tell you by experience that getting 2 BIT's more is very easy. Simply test the code on your Launchpad and put a DMM beside it. If you want to have more details, please have a look. http://www.atmel.com/dyn/resources/prod ... oc8003.pdf Bernd
  5. B.Noll

    ADC10 TestCode

    Hi Rob, I don't think so as I already explained before the resolution we can get is 2.5V / 1024 = 0.002441 Volt = 2.44 mVolt. For a 4 digit DMM you need a resolution of 1 mVolt so we need oversampling here. Lets have a look at your explanation... 2500/1023 is wrong even if you find such an example calculation in some data sheets. You have to count the 0 as well. Example: 0000000000 is your 1st return code from a 10 BIT ADC 0000000001 0000........... 1111111111 is your last so from 0 - 1023 = 1024 and your calculation is correct :-) The maximum return value is 1023 but the steps that a 10 BIT ADC can do is 1024. Cheers, Bernd
  6. B.Noll

    ADC10 TestCode

    Rob, I followed the given link but to be honest, I can not see any error correction at all. Of course and my example shows how to do it in a very effective way by also getting a 12 BIT result + Filter.
  7. B.Noll

    ADC10 TestCode

    Hi Rob, you didn't check the given code, I do not make use of floating point. I found an example that did it but of course it make no sense at all. I do all corrections by fixed point arithmetic and simple shift operations. Bernd
  8. B.Noll

    ADC10 TestCode

    Hi Mike, I use IAR EWB but inttypes.h belongs to the standard library so you should have it somewhere. http://en.wikipedia.org/wiki/Inttypes.h Have a look.
  9. B.Noll

    ADC10 TestCode

    While searching an ADC samplecode for the g2231 I found one that made use of the floating point lib to get an accurate reading of the ADC return value. As the g2231 is a 2k chip that is a silly thing to do. The goal for the code was to get an accuracy that is similar to a 4 digit DMM. Ok, let's think about this. When using the internal reference (2.5V) the resolution we can get is 2.5V / 1024 = 0.002441 Volt. We can see that the last digit will jump because 10 BIT is not enough. Ok, let's try the 2nd reference with 1.5V / 1024 = 0.001468. Not to bad but still not good enough. Also I'de like to have a range from 0-2.5 V. By testing the code I mentioned before a constant had been used to make the reading look accurate, however, as there was only one constant in use to correct the ADC the result was quite poor compared to a DMM. As we all know in real life there is no perfect ADC and if we only have the linear errors in mind we will find at least an offset and a gain error. So the problem to solve looked like: - avoid floating point - get the accuracy of floating point - correct the ADC errors - get more then 10 BIT out of the g2231 The following code will do what we need and the codesize is only 576 Byte. I used a well know oversampling technique to get 12 BIT out of the ADC and calculate all corrections by fixed point arithmetic. Instead of calculating on a base by 10 I used base 2 instead as this will allow us to get the result by a simple shift operation. Once the code was working I could still see some jumps in the last digit caused by a ripple of arround 4 mVolt caused by the poor USB powersource of the Launchpad. So I have added also a low pass filter in Software to get rid of the remaining noise. The ADC result will be displayed @ the MSP430 USB Application COM Port. I have used the Soft. Uart code by NJC but slightly modified it to have a putChar function. To adjust your ADC and get the RawValues (AdcRawHigh, AdcRawLow) for the calculation of the constants use "return (AvgSum >> 8);" instead of the original return statement "return AdcVal;" and ignore the decimal point. In function "AdcValOut" use "while (m != 4)" to display all digits of the RawValues. So here we are, let me share this code snippet with you. Please try out the code and let me know your findings. Have fun, Bernd g2231AdcTestCode.c
  • Create New...