Pages: [1]   Go Down
Author Topic: Analog read  (Read 1102 times)
0 Members and 1 Guest are viewing this topic.
malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

dut eden rockes

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what is wrong with result?
Perhaps nothing. You haven't shown any circuit or schematic or any code, though.
Logged

Offline Offline
Edison Member
*
Karma: 22
Posts: 1164
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

and the code is
Code:
/*
  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.
Logged

dut eden rockes

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 19, 2013, 03:34:21 am by dut » Logged

dut eden rockes

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24321
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey no  smiley-small..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  smiley-lol
Logged

dut eden rockes

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

yes i think this is electronic Q.
Logged

dut eden rockes

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

dut eden rockes

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

malaysia
Offline Offline
Full Member
***
Karma: 1
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

dut eden rockes

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: