This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM duty cycle error on MSP430G2433

Other Parts Discussed in Thread: MSP430G2433

Hello everyone,

I am sorry if i am repeating this question. 

I am using MSP430G2433 (Value line MSP430). I have to two A/D signals (voltage measurements) going to micro to make decision on duty cycle of one my PWM output. I dont use crystal oscillator and no A/D calibration.

Here is the deal: when i use microcontroller sample A i get 43% duty cycle with 50Hz frequency. but when i use Microcontroller sample B i get 46% duty cycle with 50Hz frequency.  

Since, frequency of PWM is same in both cases is same i don't think its issue with timer. The signals coming to micro are same as i use same interfacing circuitry. Also software is same in both.

Could anybody explain root cause of this? and how to fix it?

Thanks,

Abhishek

Thanks

  • Hi abhishek,

    I’m not sure about what you are doing, therefore I need to see the schematic.

    If using the input threshold of the port you will never get an accurate measurement. You need to add a zero-voltage detecting circuit or way.

  • Hello Leo,

    Thanks for your reply. I cant share schematic here since it offends my company policy.  Sorry for that.

    I did not understand which input threshold you talking about. The question is why there is is micro to micro variability when it is used in same interfacing circuitry. 

    Thanks,

    Abhishek

  • As I already mentioned I’m not sure if it applies to your design.

    But have a look in the Data Sheet of the MCU at the section “Schmitt-Trigger Inputs, Ports Px” there you can read the tolerances between devices.

  • abhishek Sabnis said:
    I did not understand which input threshold you talking about.

    Not applicable. You stated you were using the A/D.

    The answer lies in that you are not doing/using any A/D calibration. The calibration of the A/D is different from part to part.

    I am not sure of the details of the part you are using, but a lot of parts come with calibration values from the factory that are programmed into TLV or INFO memory. You can retrieve these values inside your running code and use them in the calculations to arrive at a calibrated reading. Read the datasheet and User's Guide for your specific device for more information and example code.

    You might also consider what the gain of your transfer function is for converting A/D reading into PWM duty cycle. Could a few millivolts of noise correspond to the 3% difference? Performance of any analog circuitry outside the MSP430 could have an effect as well.

  • Thanks Brian for your explanation. I am using MSP430G2433.

    Could you elaborated more on A/D calibration?

    Thanks,

    Abhishek

  • Information on where to find the calibration data on chip is on Page 14 of the datasheet.

    Also read Chapter 24.2.2 of the User's Guide.

    Basically you need to get the OFFSET and GAIN parameters from the chip memory and do some simple multiplication, shifting, and addition to adjust the sample.

  • Brian thanks for your information. I looked up respective values and are as shown above.

    I am using ADC10 with external reference Vref = 3.3V. SInce i never worked on modifying TLV structure could you elaborate how to do this.

    Thanks,

    Abhishek 

  • abhishek Sabnis said:
    I looked up respective values and are as shown above.

    You also need to see Table 11. Note however, that the 2433 device calibration is for external 1.5V reference, not 3.3V.

    So anyway....
      TLV ADC10 Cal data starts at memory address 0x10DA
      CAL_ADC_OFFSET is offset from that by 0x0004 (effective address 0x10DE)
      CAL_ADC_GAIN_FACTOR is offset 0x0002 (effective address 0x10DC)

    Algorithm is simple (result is unsigned):

    // Apply gain factor.
    result = (unsigned)(((unsigned long)(adc_sample * gain_factor)) >> 15);
    
    // Apply offset value
    result += offset;
    
    // Check for underflow, offset is a 16-bit signed value
    if (result & 0x8000) result = 0;

  • Brian,

    This is my ADC function where i use multiple ADC10 channels

    unsigned int ADC_read(unsigned char ChannelBit, unsigned int ChannelADC10Ctl1)
    {
    //ADC10CTL0 = SREF0 + ADC10SHT_3 + ADC10ON + REFON + REF1_5V;
    ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON;
    ADC10AE0 |= ChannelBit;
    ADC10CTL1 = ChannelADC10Ctl1;
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    timeout = 1;
    while (!(ADC10CTL0 & ADC10IFG) && ++timeout);
    result = ADC10MEM;
    ADC10AE0 = 0; //Reset A/D
    ADC10CTL0 &= ~(ENC + ADC10SC); // Sampling and conversion stop return result;
    }

    accroding to your suggestion do i need to add the piece of code you mentioned after command 

    result = ADC10MEM; to caliberate?

**Attention** This is a public forum