Forum - MCS Electronics
View previous topic :: View next topic
Author
Message
john7 Joined: 22 Nov 2006 Posts: 124
Posted: Wed Dec 05, 2007 12:13 pm Post subject: ADC on ATtiny13
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
john7 Joined: 22 Nov 2006 Posts: 124
Posted: Wed Dec 05, 2007 3:08 pm Post subject:
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
Visovian Joined: 31 Oct 2007 Posts: 584 Location: Czech
Posted: Wed Dec 05, 2007 8:42 pm Post subject:
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
john7 Joined: 22 Nov 2006 Posts: 124
Posted: Thu Dec 06, 2007 6:18 am Post subject:
Thanks a lot . It seems to be working
Back to top
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