View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 05, 2021 1:20 am Post subject: ADC in ATTINY13 |
|
|
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 |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 2:30 am Post subject: |
|
|
1023 = 5
29 = X
X = 0.1417 voltios. |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 05, 2021 2:44 am Post subject: |
|
|
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 |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 2:50 am Post subject: |
|
|
Check its potentiometer above positive +5 Vdc and below ground GND and in the middle ADC (0). |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 2:57 am Post subject: |
|
|
Are you connected PB.5 - ADC (0)? |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 05, 2021 3:06 am Post subject: |
|
|
ADC0 is Pin 1 not 5 |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 3:09 am Post subject: |
|
|
Yes ADC(0) PB.5 - PIN1 |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 05, 2021 3:13 am Post subject: |
|
|
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 |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 3:15 am Post subject: |
|
|
Potentiometer de 10 K and 5.1 volt zener. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 05, 2021 3:17 am Post subject: |
|
|
Schematic |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 3:22 am Post subject: |
|
|
How are you connected JP1? |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 3:25 am Post subject: |
|
|
JP1 at 12 volts? Feed yourself with 5 volts. |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue Jan 05, 2021 3:30 am Post subject: |
|
|
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 |
|
|
|