Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC on ATtiny13

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
john7

Bascom Member



Joined: 22 Nov 2006
Posts: 124

blank.gif
PostPosted: Wed Dec 05, 2007 12:13 pm    Post subject: ADC on ATtiny13 Reply with quote

Hi all!
I have some problems with ADC and Attiny13
I can'n get it working, PORTB.2 always high and no reaction

Code:


$regfile = "attiny13.dat"

$hwstack = 8
$swstack = 8
$framesize = 24

DDRB = &B00000011       '0 - input , 1 - output
PORTB = &B00000000
Config Pinb.2 = Input

'ADC settings
ADMUX = &B00000001       'internal ref,right adj,chan#1(pb2)
'Adcsra.7 = 1       'enable ADC
'Adcsra.6 = 0       'Stop ADC
'Adcsra.5 = 0       'autotrigger disabled
ADCSRA = &B10000110      ' prescaler = 64,

Const V_limit = 550      
Dim Adc_val As Word

Do

Gosub Get_current

Select Case Adc_val
    Case Is < V_limit : PORTB.0 = 0
    Case Is > V_limit : PORTB.0 = 1
  End Select

Loop
End


Get_current:
  ADCSRA.6 = 1       'start ADC
  Adc_val = Getadc(1)
  ADCSRA.6 = 0       'stop ADC
Return

 
Back to top
View user's profile
john7

Bascom Member



Joined: 22 Nov 2006
Posts: 124

blank.gif
PostPosted: Wed Dec 05, 2007 3:08 pm    Post subject: Reply with quote

ok i got it working, but the adc pin PORTB.2 always high!
So i have to pull it down to change the voltage - it's reverse logic.
How can i set it to work normally?
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Wed Dec 05, 2007 8:42 pm    Post subject: Reply with quote

I think, you should decide to use either Bascom statements or your own control of io registers.

If former, then
Code:

Config Adc = Single , Prescaler = Auto
Dim Adc_val As Word

Adc_val = Getadc(1)
 


If latter, then
Code:

Dim Adc_val As Word
'ADC settings
ADMUX = &B00000001       'internal ref,right adj,chan#1(pb2)
'Adcsra.7 = 1       'enable ADC
'Adcsra.6 = 0       'Stop ADC
'Adcsra.5 = 0       'autotrigger disabled
ADCSRA = &B10000110      ' prescaler = 64,


  ADCSRA.6 = 1        'start ADC
  While ADCSRA.6 = 1  'wait until conversion complete
  Wend           

  Adc_val = ADCH * 256
  Adc_val = Adc_val + ADCL
 
Back to top
View user's profile
john7

Bascom Member



Joined: 22 Nov 2006
Posts: 124

blank.gif
PostPosted: Thu Dec 06, 2007 6:18 am    Post subject: Reply with quote

Thanks a lot . It seems to be working Smile
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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