View previous topic :: View next topic |
Author |
Message |
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Wed Sep 28, 2016 2:21 pm Post subject: Run ADC on ATMega1280...??? |
|
|
Hi
how can we run ADC in the ATMega1280A chip?
i wrote a code. it work in proteus but not work in real, i get random value between 258 to 385 only. my hardware is right. i have 10uH inductor and 100nF capacitor for LCP in AVCC. AVcc and Aref pins are connected together.
i test my code with of f, Avcc, Aref, internal_1.1 and internal_2.56 for my reference voltage, but not work none.
this is my code :
Code: |
$regfile = "M1280def.dat"
$crystal = 11059200
$hwstack = 256
$swstack = 256
$framesize = 320
$baud = 9600
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Configurations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db7 = Porta.7 , Db6 = Porta.6 , Db5 = Porta.5 , Db4 = Porta.4 , E = Porta.3 , Rs = Porta.2
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variables
dim w(16) as word
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initializations
initlcd
cursor off
cls
home
lcd "Ready..."
waitms 500
cls
enable interrupts
config adc=SINGLE, prescaler=auto , REFERENCE = off
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Main Program
do
start adc
w(1)=getadc(0)
w(2)=getadc(1)
w(3)=getadc(2)
w(4)=getadc(3)
w(5)=getadc(4)
w(6)=getadc(5)
w(7)=getadc(6)
w(8)=getadc(7)
w(9)=getadc(8)
w(10)=getadc(9)
w(11)=getadc(10)
w(12)=getadc(11)
w(13)=getadc(12)
w(14)=getadc(13)
w(15)=getadc(14)
w(16)=getadc(15)
stop adc
home
lcd "0:";w(1);" 4:";w(5);" 8:";w(9)
locate 2,1
lcd "1:";w(2);" 5:";w(6);" 9:";w(10)
locate 3,1
lcd "2:";w(3);" 6:";w(7);" 10:";w(11)
locate 4,1
lcd "3:";w(4);" 7:";w(8);" 11:";w(12)
w(1)=0
w(2)=0
w(3)=0
w(4)=0
w(5)=0
w(6)=0
w(7)=0
w(8)=0
w(9)=0
w(10)=0
w(11)=0
w(12)=0
w(13)=0
w(14)=0
w(15)=0
w(16)=0
waitms 1000
loop
end
|
(BASCOM-AVR version : 2.0.7.8 ) _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Sep 28, 2016 3:23 pm Post subject: |
|
|
Hi,
I'm also using a mega1280 and don't have any problems with the adc. I'm using:-
Code: |
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
|
maybe try starting the ADC (even though the help texts says it isn't necessary).
If avcc and aref are tied together you should use avcc as your ADC reference. I'm not sure how the AVR would react if you set the reference to any other voltage than avcc.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Wed Sep 28, 2016 4:09 pm Post subject: |
|
|
Hi i.dobson
thanks alot. i try your code. but it doesn't work for me. _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Wed Sep 28, 2016 5:36 pm Post subject: |
|
|
yes...
my chip was corrupted. i change my chip and it work now.
other question. what is the best way for measuring effective voltage of a pulse train? this pulse frequency changing between 150Hz to 10KHz. _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Sep 28, 2016 6:06 pm Post subject: |
|
|
Hi,
Do you want to measure the "average voltage" or the frequency of the pulse?
For average voltage you could use a RC filter (resistor & capacitor)
For frequency maybe try using an Interrupt Input that fires on a rising or falling edge, and Count the number of pluses per second.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Thu Sep 29, 2016 12:11 am Post subject: |
|
|
yes, i want to measure average voltage and frequency. i measure frequency and don't have problem with it. but in measuring average voltage i have problem.
i not use RC filter yet. what is R and C value? i think it depend on frequency but we have a wide range of frequency(150Hz to 10Khz).
how can we calculate R and C value? _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Sep 29, 2016 11:14 am Post subject: |
|
|
Hi,
Have a look here http://sim.okawa-denshi.jp/en/CRtool.php that should help you calculate the correct values for R&C.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Fri Sep 30, 2016 9:56 pm Post subject: |
|
|
thank you i.dobson
i calculate my R and C value for this low pass filter. but it can pass my frequency just. my problem is my ADC value does change very very fast and i don't have a steady state for ADC value. _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
|
Back to top |
|
|
Ajaxelectronic
Joined: 22 Nov 2009 Posts: 171 Location: Iran
|
Posted: Sat Oct 01, 2016 5:52 pm Post subject: |
|
|
thanks a lot
i buy an IC for convert RMS to Dc value. my chip is AD736 and i want to running it. i thinks this is better way.
thanks again _________________ www.mrkelectronic.blogfa.com
Best Regards |
|
Back to top |
|
|
|