Jump to content

watergius

Members
  • Content Count

    16
  • Joined

  • Last visited

  1. Thank you RobG.. I have just tested it, and there are no more voltage drop/increase..
  2. RobG, what you mean with jumper is that little black thing that can be revoked right? I haven't, it's still attach. Okay, I will try it. Thank you for your suggestion.
  3. Hello.. I was trying to use ADC10 in MSP430G2231. The input were from two voltage dividers as this schematic shows: and the code for my ADC is something like this: #include #include "msp430g2231.h" // Variable Definitions volatile int voltage; // Voltage value from next measurement volatile int current; // Current value from next measurement int power; // Power value from next measurement int initV; // Voltage Initial value int initI; // Current Initial value int initP; // Power initial value void main (void){ WDTCTL = WDTPW + WDTHOLD; // kill watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ADC10 on, 4 clock cycles per sample, Use Vcc/Vss references ADC10AE0 |= BIT0 + BIT1 ; // P1.0 or P1.1 ADC option select P1DIR |= BIT2; // P1.2 = output P1SEL |= BIT2; // P1.2 = TA1 output TACCTL1 = OUTMOD_7; // TACCR1 reset/set TACTL = TASSEL_2 + MC_1; // SMCLK, upmode TACCR0 = 1024-1; // PWM Period initV = 801; // voltage initial value, equal to Vmpp initI = 87; // current initial value, equal to Impp initP = (initV * initI)/2^10; // power initial value, change it back to 10 bit TACCR1 = initP; // TACCR1 PWM Duty Cycle while (1) { voltage = analogRead(INCH_0); // voltage read from analog input current = analogRead(INCH_1); // voltage drop for current sensing from analog input power = (voltage*current)/2^10; // change it back to 10 bit TACCR1 = power; // output PWM } } /** * Reads ADC 'chan' once using AVCC as the reference. **/ int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_3 + pin;// Select SMCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; } it's working (can produce PWM). Then, I decided to check the voltage in ADC input. First, I check each voltage in voltage divider output (ADC1 and ADC2). After that, I connect the voltage divider to the ADC input port (P1.0 and P1.1) and check the voltage back. Here was the result that I got: Then, I try to improve by turn off the power source (both MSP and Voltage divider) for a short time and turn it on again, then measure it back. This was the result that I got: But, if I turn of the power source (both MSP and Voltage divider) for quite a long time and turn it on again , the result was like the first measurement (before I turn in off). That's why I would like to ask is this normal or is it has something to do with the code that I wrote? I need an exact reading of ADC input so a big voltage drop or rising like that unaccepted. And also, does ADC input pin in MSP430G2231 design for specific voltage because from my first measurement, it's kind of show this. Thank you for any helps and comments.
  4. finally I try use another MSP430 and change the Vcc to 3.3 Volt and the frequency is stable.. whether my previous MSP430 that was broken or is it because the Vcc, I don't know for sure..
  5. @hvontres : sorry for the late reply because I'm out of town for two days.. actually I'm trying to control a boost DC converter with this PWM.. The minimum requirements of my DC Boost Converter stated that it needs a 10 kHz frequency (I assume that it is equal to PWM frequency).. That's why I need that kind of stable/constant frequency.. Meanwhile, the duty cycle of my PWM needs to be changed according to the ADC input (voltage and current). ADC input is 10 bit (1023), that's why after I multiply the voltage and current I need to divide it back to 10 bit using 2^10.. Now, I got the "power" variable within the range 0-1023 which then I assign to TACCR1 register.. Because of that, I also need a maximum period around 1023 resulting in TACCR0 equal to 1023.. But, like you said before, this is the reason why I only got frequency around 1 Khz even though I set the DCO and SMCLK around 1 MHz.. I hope you can understand what I said.. And, do you have any suggestions on how to solve the problem.. Thanks
  6. @hvontres : now it makes sense why I only got PWM frequency around 1 kHz (because 1 MHz/1024 is 0.976 kHz) now, if I want to produce PWM that has a frequency 1 MHz, can you please tell me what should I change? Should I decrease the TACCR0 or what? And, about my frequency that keeps changing when I use ADC, do you know what cause it? thanks @bluehash : When I tried to generate only the PWM using this code #include "msp430G2231.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz P1DIR |= BIT2; // P1.2 to output P1SEL |= BIT2; // P1.2 to TA0.1 CCR0 = 1024-1; // PWM Period CCTL1 = OUTMOD_7; // CCR1 reset/set CCR1 = 250; // CCR1 PWM duty cycle TACTL = TASSEL_2 + MC_1; // SMCLK, up mode } , the frequency is constant. And now I know why I got the frequency only around 1 kHz even though I set it for 1 MHz.
  7. I am sorry, but I didn't know what you mean with "scope's Frequency calculation".. is it in the oscilloscope? forced the ADC value to a constant, you mean like making a constant duty cycle and not use the ADC at all, right ?.. I've tried. The frequency did stop changing, but still, it is not produced the frequency that I wanted.. I tried to produce 1 MHz frequency using this line : BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz but I only got around 1 kHz.. Is there's something wrong with my MSP430?
  8. Hello guys.. I am trying to produce PWM with its duty cycle comes from the multiplication of two analog inputs. This is the code that I use : #include #include "msp430g2231.h" // Variable Definitions volatile int voltage; // Voltage value from next measurement volatile int current; // Current value from next measurement int power; // Power value from next measurement int initV; // Voltage Initial value int initI; // Current Initial value int initP; // Power initial value void main (void){ WDTCTL = WDTPW + WDTHOLD; // kill watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ADC10 on, 4 clock cycles per sample, Use Vcc/Vss references ADC10AE0 |= BIT0 + BIT1 ; // P1.0 or P1.1 ADC option select P1DIR |= BIT2; // P1.2 = output P1SEL |= BIT2; // P1.2 = TA1 output TACCTL1 = OUTMOD_7; // TACCR1 reset/set TACTL = TASSEL_2 + MC_1; // SMCLK, upmode TACCR0 = 1024-1; // PWM Period initV = 801; // voltage initial value, equal to Vmpp initI = 87; // current initial value, equal to Impp initP = (initV * initI)/2^10; // power initial value, change it back to 10 bit TACCR1 = initP; // TACCR1 PWM Duty Cycle while (1) { voltage = analogRead(INCH_0); // voltage read from analog input current = analogRead(INCH_1); // voltage drop for current sensing from analog input power = (voltage*current)/2^10; // change it back to 10 bit TACCR1 = power; // output PWM } } /** * Reads ADC 'chan' once using AVCC as the reference. **/ int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_3 + pin;// Select SMCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; } it seems to work because I can produce PWM. But, there is a problem. The frequency keeps changing and its not even 1 MHz (only around 1 kHz max). This is the video: Can anybody please tell me what's wrong and what should I do/fix.. Any helps and suggestions are appreciate..
  9. @SoulSLayer : it's okay.. and about your previous comment about CCR0, when you make the CCR0 = 1024, I guess you wouldn't be able to get duty cycle 100% since the CCR1 value is 1023 * (Vin/Vref)-> which means that the maximum value is 1023.. well, that's just my opinion..
  10. I've been post the same topic before (http://43oh.com/forum/viewtopic.php?f=8&t=887) but unable to make it work using that algorithm. So, I try another way like this thanks to this blog (http://blog.suspended-chord.info/?c=17) : #include #include "msp430g2231.h" // Variable Definitions volatile int voltage; // Voltage value from next measurement volatile int current; // Current value from next measurement void main (void){ WDTCTL = WDTPW + WDTHOLD; // kill watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ACD10 on, 4 clock cycles per sample, Use Vcc/Vss references ADC10AE0 |= BIT0 + BIT1 ; // P1.0 or P1.1 ADC option select P1DIR |= BIT2; // P1.2 = output P1SEL |= BIT2; // P1.2 = TA1 output TACCTL1 = OUTMOD_7; // TACCR1 reset/set TACTL = TASSEL_2 + MC_1; // SMCLK, upmode TACCR0 = 1024-1; // PWM Period voltage = 32; current = 16; TACCR1 = voltage*current*0.002; // TACCR1 PWM Duty Cycle while (1){ voltage = analogRead(INCH_0); current = analogRead(INCH_1); TACCR1 = voltage*current*0.002; // TACCR1 PWM Duty Cycle } } /** * Reads ADC 'chan' once using AVCC as the reference. **/ int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_3 + pin;// Select SMCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; } I try to compile and debug it, and nothing goes wrong. Then, since I don't have an oscilloscope with me right now, I try to connect the PWM output (pin P1.2) to a LED. Then I vary the analog input (P1.0 and P1.1) and the LED brightness change. So, I guess it's working. So, I just want to know what you guys think of it. Do I make it right? And I want to make it as efficient as possible (low power consumption), but apparently I don't really know how to use the interrupt. So, any suggestions and corrections are greatly appreciate. Thanks
  11. @RobG : what do you mean with "address of" ? Is it the address of the AdcData? with the code example that you provide, that means that I should write something like this, right: ADC10SA = (unsigned int)&AdcData; // Data transfer location My AdcData is an array which consist of AdcData[0] (for storing converted ADC value from P1.0) and AdcData[1] (storing converted ADC value from P1.1). Or, do I need to assign the ADC10SA like this : ADC10SA = (unsigned int)&AdcData[0]; to indicate the address started at AdcData[0] ? thanks
  12. actually the step button is not a real button (not physical).. It is a button in debugging mode to check whether the value in a specific register correct or not (I got it from this tutorial : http://mspsci.blogspot.com/2010/07/tutorial-06-getting-bugs-out.html) I try to track it because when I run the codes/algorithm, the PWM is not working and the value in all registers are unable to read.. And about the pointer itself, I don't really know whether it's wrong or not. I copied it from this code example (msp430g2x31_adc10_16.c) and it working right there. And I also try it with and without the pointer (&) for the AdcData :| thanks.
  13. thank you all for giving me feedback.. Actually I've been writing the algorithm like you mention and it goes like these and it still not working for (; { ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ADC10SA = (unsigned int)&AdcData; // Data transfer location ADC10CTL0 |= ENC + ADC10SC; // Start sampling __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { //code from reading from res and sending it to AP __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) } the only difference is, now the "step into" button not working when it reaches the line after __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit I don't use this code : P1OUT |= 0x01; because I use that Pin for ADC input. And this line, ADC10SA = 0x200; // Data buffer start ADC10SA means ADC10 Start Address right, where you want to transfer the ADC conversion value? So, when I want to transfer it to my AdcData array, is it okay to write it like it did? thanks
  14. I have tried it RobG, but it still not working.. any other solution?
  15. Hello guys.. I am a newbie to this MSP430. So, please tell me when I go wrong. I have a final project making MPPT (Maximum Power Point Tracker) using MSP430G2231. The basic idea is to measure to Analog input (voltage and current), then multiply it (power) and compare to the previous result. That's why, before going further to the algorithm of the MPPT itself, I am trying to use this MSP430G2231 to read 2 analog input and create PWM using it. I use two pins as an input, P1.0 and P1.1. Then, I use P1.2 to produce the PWM. The coding that I made goes like this: #include #include "msp430g2231.h" //Global Variable unsigned int AdcData[2] ; // Store results A1,A0 unsigned int Current ; // store value from P1.0 unsigned int Voltage ; // store value from P1.1 void main (void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz ADC10CTL1 = INCH_1 + CONSEQ_1; // A1/A0, single sequence ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; ADC10DTC1 = 0x02; // 2 conversions ADC10AE0 |= 0x03; // P1.1,0 ADC10 option select P1DIR |= BIT2; // P1.2 = output P1SEL |= BIT2; // P1.2 = TA1 output TACCR0 = 1024-1; // PWM Period TACCTL1 = OUTMOD_7; // TACCR1 reset/set AdcData[0]=32; AdcData[1]=16; Voltage = AdcData[0]; Current = AdcData[1]; TACCR1 = (Voltage*0.04)*(Current*0.05); // TACCR1 PWM Duty Cycle TACTL = TASSEL_2 + MC_1; // SMCLK, upmode while (1) { __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC10_ISR will force exit ADC10SA = (unsigned int)AdcData; // Data transfer location ADC10CTL0 |= ENC + ADC10SC; // Start sampling } } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 } And it doesn't goes well.. I try to trace it using "step into" in debugging mode. Everything seems goes well until it reach this line : ADC10SA = (unsigned int)AdcData; // Data transfer location When the pointer reach that line, the "step into" button is not active anymore which means there's something wrong.. Do I write the algorithm right, especially when assign the values from ADC to the AdcData? Any helps are greatly appreciate. Thank you.
×
×
  • Create New...