Go Down

### Topic: Analog read (Read 4633 times)previous topic - next topic

#### mrdutx

##### Apr 19, 2013, 06:13 am
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?

#### PaulS

#1
##### Apr 19, 2013, 07:37 am
Quote
what is wrong with result?

Perhaps nothing. You haven't shown any circuit or schematic or any code, though.
The art of getting good answers lies in asking good questions.

#### DVDdoug

#2
##### Apr 19, 2013, 08:28 am
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)

Quote
...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.

#### mrdutx

#3
##### Apr 19, 2013, 08:30 am
sorry ,
ok  here wat i do.. the circuit is here

and the code is
Code: [Select]
`/*  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))#endifint value[100];   // variable to store the value coming from the sensorint 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.

#### Grumpy_Mike

#4
##### Apr 19, 2013, 09:30 am
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.

#### mrdutx

#5
##### Apr 19, 2013, 10:18 amLast Edit: Apr 19, 2013, 10:34 am by dut Reason: 1
Quote
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,

Quote
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.

#### Grumpy_Mike

#6
##### Apr 19, 2013, 10:26 am
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.

#### AWOL

#7
##### Apr 19, 2013, 10:35 am
Is this really a programming question?
Should I move this to "General Electronics"?

#### mrdutx

#8
##### Apr 19, 2013, 10:37 am
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

#### mrdutx

#9
##### Apr 19, 2013, 10:46 am

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

yes i think this is electronic Q.

#### mrdutx

#10
##### Apr 20, 2013, 05:36 am

Quote
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,

Quote
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?

#### Grumpy_Mike

#11
##### Apr 20, 2013, 10:10 am
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.

#### mrdutx

#12
##### Apr 22, 2013, 04:58 am
hi mike, i have modify the circuit.. like this..
tell me if im wrong

#### Grumpy_Mike

#13
##### Apr 22, 2013, 09:21 am
Yes it is wrong the capacitor should be between the two potential dividers.

Go Up