Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC in ATTINY13
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 1:20 am    Post subject: ADC in ATTINY13 Reply with quote

I've been using the ADC in Mega128, 2561 and 2560 for years and never had an issue. However, I have a need for a very simple voltage comparator and figured I'd press some Tiny13's I have laying around into service for it

Code:
$regfile = "attiny13.dat"
$hwstack = 10
$swstack = 10
$framesize = 16

RELAY Alias Pinb.0

Config Pinb.0 = Output

Const True = 1
Const False = 0

Config ADC = Single , Prescaler = Auto
Start ADC

Pinb.0 = False
Do
 
  If GetADC(0) < 29 Then
      RELAY = True                                          'energize
     Else
      RELAY = False                                         'de-energize
    End If
End If

Loop


29 is the value that represents the voltage threshold I'm looking for. But Pinb.0 only goes up to approx .5 volts when a logic high

Am I overlooking something?

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 2:30 am    Post subject: Reply with quote

1023 = 5
29 = X

X = 0.1417 voltios.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 2:37 am    Post subject: Reply with quote

not that way.

Code:
 If GetADC(0) < 29 Then
      RELAY = True                                          'energize
     Else
      RELAY = False                                         'de-energize
    End If
End If

 


This is how the instructions are written.

Code:
 If GetADC(0) < 29 Then
  RELAY = True                                          'energize
  Else
  RELAY = False                                         'de-energize
 End If
 



Very Happy Very Happy
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 2:43 am    Post subject: Reply with quote

Printpix52 wrote:
not that way.

Code:
 If GetADC(0) < 29 Then
      RELAY = True                                          'energize
     Else
      RELAY = False                                         'de-energize
    End If
End If

 


This is how the instructions are written.

Code:
 If GetADC(0) < 29 Then
  RELAY = True                                          'energize
  Else
  RELAY = False                                         'de-energize
 End If
 



Very Happy Very Happy


Oops..typo Obviously there is only end End If statement...good catch!
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 2:44 am    Post subject: Reply with quote

Printpix52 wrote:
1023 = 5
29 = X

X = 0.1417 voltios.

Yes but that doesn't explain why I'm only seeing .5 volts as a logic high (the transition above and below works ok)
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 2:50 am    Post subject: Reply with quote

Check its potentiometer above positive +5 Vdc and below ground GND and in the middle ADC (0).
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 2:57 am    Post subject: Reply with quote

Are you connected PB.5 - ADC (0)?
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 3:06 am    Post subject: Reply with quote

ADC0 is Pin 1 not 5
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 3:09 am    Post subject: Reply with quote

Yes ADC(0) PB.5 - PIN1
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 3:13 am    Post subject: Reply with quote

Yes. connected to physical pin 1 through a 470 ohm resistor with a 5.1 volt zener diode to ground on the pin 1 side
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 3:15 am    Post subject: Reply with quote

Potentiometer de 10 K and 5.1 volt zener.
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

blank.gif
PostPosted: Tue Jan 05, 2021 3:17 am    Post subject: Reply with quote

Schematic
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 3:22 am    Post subject: Reply with quote

How are you connected JP1?
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 3:25 am    Post subject: Reply with quote

JP1 at 12 volts? Feed yourself with 5 volts.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Jan 05, 2021 3:30 am    Post subject: Reply with quote

In the schematic representation we can see that the fixed terminals are 1 and 2, while the cursor is the number 3, which is represented by an arrow.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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