Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Run ADC on ATMega1280...???

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Wed Sep 28, 2016 2:21 pm    Post subject: Run ADC on ATMega1280...??? Reply with quote

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
View user's profile Visit poster's website Yahoo Messenger
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Wed Sep 28, 2016 3:23 pm    Post subject: Reply with quote

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
View user's profile
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Wed Sep 28, 2016 4:09 pm    Post subject: Reply with quote

Hi i.dobson

thanks alot. i try your code. but it doesn't work for me. Crying or Very sad Crying or Very sad Crying or Very sad

_________________
www.mrkelectronic.blogfa.com

Best Regards
Back to top
View user's profile Visit poster's website Yahoo Messenger
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Wed Sep 28, 2016 5:36 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website Yahoo Messenger
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Wed Sep 28, 2016 6:06 pm    Post subject: Reply with quote

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
View user's profile
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Thu Sep 29, 2016 12:11 am    Post subject: Reply with quote

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
View user's profile Visit poster's website Yahoo Messenger
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Thu Sep 29, 2016 11:14 am    Post subject: Reply with quote

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
View user's profile
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Fri Sep 30, 2016 9:56 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website Yahoo Messenger
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Oct 01, 2016 7:19 am    Post subject: Reply with quote

Hi,

Maybe try increasing the value of C. Also try measurung the voltage with a Volt meter. You might Need to use a Software filter on the AVR (have a look here for a good example http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13285&highlight=smoothing ).

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Sat Oct 01, 2016 5:52 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum