Analog read

hey i read and old topic for fast analog read here http://arduino.cc/forum/index.php?PHPSESSID=2a664108e1246eeac25151f80e987a67&topic=6549.15

i try this code on my arduino to get ac signal from transformer 50hz. but why i did not have the sinus graph instead square wave i get here

what is wrong with result?

what is wrong with result?

Perhaps nothing. You haven't shown any circuit or schematic or any code, though.

It looks like your voltage may be high (or your reference too low). How much AC voltage are you feeding-in?

Remember that (with a sine wave) the peak voltage is about 1.4 times the RMS and peak-to-peak voltage is about 2.8 times RMS. The maximum peak-to-peak voltage has to be less than 5V if you want to accurately read the waveform (without clipping). That means your AC voltage should be less than about 1.75V RMS (with a 5V reference)

...to get ac signal from transformer 50hz.

You won't be able to read the negative AC half-cycle (unless you add some bias) and you can damage the Arduino if you feed-in negative voltages, or voltages greater than +5V.

sorry , ok here wat i do.. the circuit is here and the code is

/*
  Analog Input with prescale change
  Reading a 1 kHz sine wave, 0 to 5 volts
  Using analog 0
  Results stored in memory for highest speed
  using code from:
  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11
  with special thanks to jmknapp
 */

#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

int value[100];   // variable to store the value coming from the sensor
int i=0;

void setup() 
{
   Serial.begin(9600) ;
  int start ;
  int i ;
  
#if FASTADC
  // set prescale to 16
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  cbi(ADCSRA,ADPS0) ;
#endif
}

void loop() 
{ 
 for (i=0;i<100;i++)
{
  value[i]=analogRead(0);
} 
for (i=0;i<100;i++)
{
  Serial.println(value[i]);
} 
Serial.println();
Serial.println();
Serial.println();
delay(5000);
  
}

now the result look like this (plot in excel ) . what im try to do is get the sinus graph from the ac supply. how can i do that.

First off that will feed -5V into the arduino which will damage it. Next as said the peak voltage for a 12V AC signal is not 12V but 12 times 1.4

You can not get what you want with that schematic. You need to apply a 2.5 V bias to the analogue input and then AC couple into it ( use a capacitor), then change that bottom resistor to 3K3.

First off that will feed -5V into the arduino which will damage it.

but i mesured with multimeter it show 5V. i set VR to 14kOhm. the out put to arduino pin is 5V Grumpy_Mike,

Next as said the peak voltage for a 12V AC signal is not 12V but 12 times 1.4

what u mean it by 12 time 1.4? is the output will be 16.8V. it not verry clear to me.

You are asking questions and then arguing with the answer!

Your meter measures 5V on its AC setting. That is measuring the RMS value of the voltage, it is not the peak nor is it the peak to peak reading. To get the peak reading from the RMS value you multiply it by 1.4, so yes the peak value you get from 12V AC is 16.8V.

You need to look up your basic AC theory.

Is this really a programming question? Should I move this to "General Electronics"?

hey no :…sorry mike, im not arguing with u,

i see now, so what i measure is not Vp-p value…ok i will modify the circuit and see the result…thank mike XD

AWOL: Is this really a programming question? Should I move this to "General Electronics"?

yes i think this is electronic Q.

dut:

First off that will feed -5V into the arduino which will damage it.

but i mesured with multimeter it show 5V. i set VR to 14kOhm. the out put to arduino pin is 5V Grumpy_Mike,

Next as said the peak voltage for a 12V AC signal is not 12V but 12 times 1.4

what u mean it by 12 time 1.4? is the output will be 16.8V. it not verry clear to me.

how to make bias to my circuit mike?

Two resistors of 1K attached to the analogue input. The other ends go to +5V and ground. Then the input sits at 2.5V and your capacitor attaching it to the AC source can pull it up and down from this point.

hi mike, i have modify the circuit.. like this.. tell me if im wrong

Yes it is wrong the capacitor should be between the two potential dividers.