Hi, i am trying do work one ADC, but he work one time, when he will convert again he dont work, he stop in this line while (ADC10CTL1 & BUSY); look my code
----------------------------------------
main code
InitLCD(); initadc(); while(1){ adc(); letensao(); lecorrente(); }
--------------------------------------
initadc()
-----------------------------------
void initadc(){ ADC10CTL1 = INCH_1 + CONSEQ_1; // /A2/A1, sequência simples ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V; ADC10DTC1 = 0x02; // 2 conversões ADC10AE0 |= 0x03; // P1.1, 1.0 entradas ADC10 }
-------------------------------
adc()
------------------------------ float volt; float current; ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); // Aguarda até o ADC10 estar ativo ADC10SA = (unsigned int)&conv_ADC10; // Inicializa o buffer de dados ADC10CTL0 |= ENC + ADC10SC; // Inicia a amostragem/conversão volt = ((2.5*conv_ADC10[0])/1023); current = ((2.5*conv_ADC10[1])/1023); __delay_cycles(200); grava_valor(volt,endetensao,86); __delay_cycles(200); grava_valor(current,endecorrente,65); // leitura da corrente
grava_valor is one function that records the value in the flash memoryletensao() and lecorrente() are functions that show the values recorded in the memory flash in the LCD
------------------------
the trouble is that this function convert ADC just one time, when he will convert again, he stop. What the happen? why he stop?
anyone?
felipe pauloanyone?
felipe paulo ADC10CTL0 |= ENC + ADC10SC; // Inicia a amostragem/conversão volt = ((2.5*conv_ADC10[0])/1023);
You'll have to check (worst but simplest case with a busy-waiting while loop) whether the ADC has done its job.
felipe paulo ADC10CTL1 = INCH_1 + CONSEQ_1; // /A2/A1, sequência simples ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
felipe paulo volt = ((2.5*conv_ADC10[0])/1023);
felipe paulo ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
Jens-Michael Gross, this some time i can do with __delay_cycles()? Or i have to do with timer?
worked, i change ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V; TO ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + MSC + REF2_5V; ..... I do this to measure the power consumer. But to do this i have to multiplicate all points of measure to find the wave of power and after calculate the average power. Do you have some idea how i do this?
felipe paulothis some time i can do with __delay_cycles()? Or i have to do with timer?
felipe paulo I do this to measure the power consumer. But to do this i have to multiplicate all points of measure to find the wave of power and after calculate the average power.
Yes, but how do I get the point of conversion? because the program gives me the result only when the conversion ends. If a can get the points, i can multiply the wave of de voltage and current, find the wave of power and after calculate the average. I don´t know how i do this in the MSP430
I don't really understand what you mean. Sure you can only get the conversion result once it is ready. One conversion, one 'point'. Available when taken.It's your programs job to request values when you need them, or take continuously incoming conversions results into a context. Your code just requests one pair of values, then does the calculation and then returns. If this is not what you want, then you need to change the concept of your code.
The DTC can trigger an interrupt whenever a pair of conversions is done, so in an ISR for this interrupt, you can take the two and do whatever you want (multiply, tag them with a timestamp derived from a timer, check for zero-crossing etc.) while the ADC continues making the next sequence of conversions.