Hi!
Here is my code. It is able to measure the two analog inputs, also the counter on P1.1 is fine. I am not able to copy the content to a variable. I do not know why. Does anyone has a solution?
Thank You.
[/code]
#include <msp430x20x3.h>
//#include <>
void power_compare(void);
void cap_state(void);
unsigned int U;
unsigned int i;
//unsigned int d=0;
unsigned short Usp;
unsigned int Ucap;
unsigned long I;
unsigned int roll =0;
unsigned int charge = 1;
unsigned int period = 20;
unsigned int DC=1;
unsigned int prevP=0;
unsigned long int P=0;
int a1;
int a2;
int a3;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = 0x0D; // pin P1.0,P1.2,P1.3 output
P1DIR |= 0x04; // P1.2 and P1.3 output
P1SEL |= 0x04; // P1.2 and P1.3 TA1/2 options
CCR0 = period; // PWM Period/2
CCTL1 = OUTMOD_7; // CCR1 toggle/set
CCR1 = DC; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up-down mode
while(1)
{
a1=1;
P1IE |= 0x02; // P1.4 interrupt enabled
P1IFG &= ~0x10; // P1.4 IFG cleared
_BIS_SR(GIE);
//a1=1;
while(a1){}
P1IE &= ~0x02; // interrupr disabled
SD16CTL = SD16REFON + SD16SSEL_1; // 1.2V ref, SMCLK
SD16INCTL0 = SD16INCH_2 ; // A2+/-
SD16CCTL0 = SD16UNI + SD16IE; // 256OSR, unipolar, interrupt enable
SD16AE = SD16AE4; // P1.4 A2+,P1.6 A3+ A1- = VSS
SD16CCTL0 |= SD16SC; // Set bit to start conversion
Usp=U;
SD16CCTL0 &= ~SD16IE;
SD16CTL = SD16REFON + SD16SSEL_1; // 1.2V ref, SMCLK
SD16INCTL0 = SD16INCH_3; // A1+/-
SD16CCTL0 = SD16UNI + SD16IE; // 256OSR, unipolar, interrupt enable
SD16AE = SD16AE6; // P1.1 A1+, A1- = VSS
SD16CCTL0 |= SD16SC; // Set bit to start conversion
Ucap=U;
SD16CCTL0 &=~SD16IE;
_BIS_SR(GIE);
power_compare();
cap_state();
prevP=P;
CCR1=DC;
}
}
// interrupt of ADC16:
#pragma vector = SD16_VECTOR
__interrupt void SD16ISR(void)
{
U=SD16MEM0;
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
I=0;
while(P1IN & 0x02) // Current Measurement
I=I+1; // count current duty-cycle length
a1=0;
P1IFG &= ~0x02; // P1.4 IFG cleared
}[/code][/code]