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.

electronic load controller

Other Parts Discussed in Thread: MSP430F2234

iam using the msp430f2234 ADC to sample a voltage 0-3.6V 50Hz reduced from the 230V, 50Hz, and trigger a triac when the voltage is 1.8,

am finding problems sampling the wave, code would be of great help. i have attached a copy of my voltage reducing circuit 

below is my sample code

#include <msp430x22x4.h>
volatile unsigned int i; // volatile to prevent optimization
double adc_value[1] = {0};


void main(void){

WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;                       // Set range
DCOCTL = CALDCO_1MHZ;



P1DIR |= 0x01; // Set P1.0 to output direction
P2DIR |=0xF8;                               // Set ports P2.0/1/2 to Input Direction
P2SEL |=0x07;                               // Select Ports P2.0/1/2 as analogue input function

ADC10CTL0 =ADC10ON + REF2_5V + ADC10SHT_3 + ENC + ADC10SC + MSC;                  //ADC ON, Reference Voltage to 2.5 V and select Up-mode
ADC10CTL1 = INCH_1 +CONSEQ_1;             // Select A1 as input channel, repeat single channel as conversion sequence
ADC10DTC0 = ADC10CT;                      // continuous data transfer

__delay_cycles(1000);
 ADC10CTL0 |= ENC + ADC10SC;                  // Sampling and conversion start
  adc_value[0] = ADC10MEM;
      if ( adc_value[0] = 1011100000) {
            __delay_cycles(16000);
            P1OUT = BIT0; // high P1.0
            __delay_cycles(100);
            P1OUT &= ~0x01;
            }
 
    else{
    P1OUT &= ~0x01;
 }
 
 }
 

  • In the shown circuit, what is the input voltage swing? 230VAC?
    Looking at R1, R2, R5, the voltage eon R5 is Uin*R5/(R1+R2+R5). This alone would give an output voltage of 0.38*Vin. However, The pot and R4 are parallel to R5, which reduces the resistance and therefore the output voltage. But then again, D1, R3 and R4 are parallel to R5 too. Calculation is a bit more complex here, but a rough estimation gives 0.028*Vin +0.7V. = ~10Vpeak. Which is far too much for the MSP input. Well, the current won’t exceed 0.6mA, so the MSP’s clamp diodes will protect it from being scorched.
    I’d use a different setup: A 2.7V Zener diode instead of R5, replacing D2, D2, C1, R3 and R4, the POT parallel to the zener, with the wiper connected to the MSP. In case of diode failure, the maximum current will be limited to 0.6mA by R1/R2, so this is safe. And on normal operation, voltage will rise from 0V (zero crossing) to zener voltage without division (well, almost, as the MSP input has limited impedance) and is then cut-off at the zener voltage. You might want to put a low-voltage-drop diode parallel to the zener, so that negative voltage is limited better than the zener would do it. However, negative current is still limited to 0.6mA, so the MSP won’t have problems.

     Now about your software. IIRC, CONSEQ_1 is single sequence, not repeated single mode.
    You shouldn’t set ADC10SC at setup. It starts the conversion while you haven’t set-up the DTC yet and the reference hasn’t settled. Also, better don’t set ADC10ENC there too.

    After starting the conversion, wait until it is done. Your code sets ADC12ENDc and immediately reads the result. The ADC is independent form the CPU. The CPU won’t wait until the conversion is done. You have to wait for the ADC flagging you that it is done by the ADC10IFG bit.
    You program ADC10DTC0, but do not set-up the DTC properly. And you don’t need to. Forget about ADC10DTC0 if you don’t want to use the auto-storage of ADC results.

    Your P1.0 pulse is only 100µs. Is this long enough for the triac? What about the Q1 collector/basis breakthrough voltage? Worst case you have 325V or more here. So be sure to have a 500V transistor.

**Attention** This is a public forum