Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC in ATTINY13
Goto page Previous  1, 2
 
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 3:35 am    Post subject: Reply with quote

Printpix52 wrote:
JP1 at 12 volts? Feed yourself with 5 volts.


IC2 is a 5 volt regulator
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

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

Printpix52 wrote:
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.


I don't follow
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:37 am    Post subject: Reply with quote

KenHorse wrote:
Printpix52 wrote:
JP1 at 12 volts? Feed yourself with 5 volts.


IC2 is a 5 volt regulator



Yes.
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:41 am    Post subject: Reply with quote

How are you connected outside 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:44 am    Post subject: Reply with quote

KenHorse wrote:
Schematic


Is it a battery charger? what do you use this circuit for? Surprised Surprised
Back to top
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 523

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

When the voltage drops below "29", de-activate a relay. When it rises above, activate the relay
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:52 am    Post subject: Reply with quote

KenHorse wrote:
When the voltage drops below "29", de-activate a relay. When it rises above, activate the relay


Yes, the maximum ADC input voltage is 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:56 am    Post subject: Reply with quote

Code:
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
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 4:28 am    Post subject: Reply with quote

Very Happy Very Happy Very Happy Smile Smile

Try these as it works fine.

Code:
$regfile = "m328pdef.dat"
$Crystal=16000000
$hwstack=40
$swstack = 16
$framesize = 32

$sim
$baud = 9600

RELAY Alias Pinb.0

Config Pinb.0 = Output

Const True = 1
Const False = 0

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Start Adc

Dim W As Word

Pinb.0 = False
Do

  W = Getadc(0)


  If W < 29 Then
      Relay = True
      Print "True"
      Waitms 100                                            'energize
      Else
      Relay = False
      Print "False"
      Waitms 100                                            'de-energize
  End If

Loop
End



Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Tue Jan 05, 2021 4:55 am    Post subject: Reply with quote

Hi,
Pin 1 (ADC0) is a RESET pin, so unless you change the fuse settings, it will reset at the [L] level.
If the voltage is higher than the reset level, it will function as ADC0.
It works if you change it to pin 2 (ADC3).
Also, when outputting to a port, it is Portb.0 instead of Pinb.0.
Code:
$regfile = "attiny13.dat"
$hwstack = 10
$swstack = 10
$framesize = 16

$crystal = 1200000

Relay Alias Portb.0
Config Relay = Output

Const True = 1
Const False = 0

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start ADC

Relay = False

Do
   If Getadc(3) < 29 Then
      Relay = True                                          'energize
   Else
      Relay = False                                         'de-energize
   End If
Loop

End
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Thu Jan 07, 2021 3:39 am    Post subject: Reply with quote

O-Family wrote:
Hi,
Pin 1 (ADC0) is a RESET pin, so unless you change the fuse settings, it will reset at the [L] level.
If the voltage is higher than the reset level, it will function as ADC0.
It works if you change it to pin 2 (ADC3).
Also, when outputting to a port, it is Portb.0 instead of Pinb.0.
Code:
$regfile = "attiny13.dat"
$hwstack = 10
$swstack = 10
$framesize = 16

$crystal = 1200000

Relay Alias Portb.0
Config Relay = Output

Const True = 1
Const False = 0

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start ADC

Relay = False

Do
   If Getadc(3) < 29 Then
      Relay = True                                          'energize
   Else
      Relay = False                                         'de-energize
   End If
Loop

End
Back to top
View user's profile
Micha

Bascom Member



Joined: 03 Oct 2006
Posts: 57

germany.gif
PostPosted: Thu Jan 07, 2021 6:34 am    Post subject: Reply with quote

You need to set:

$Crystal = ?

and

Config ADC = ... , Reference = ?
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 Previous  1, 2
Page 2 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