Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

adc trouble with 16f628A

Status
Not open for further replies.

Goos_E

New Member
when i try to compile a basic program that reads ADC0 then i got a popup saying that this microcontroller doesn't feature a/d converter module. but when i read the 40044 pdf file from microchip that says there are 2 analog comperator modules present. What am i doing wrong.
 
Well it's a Comparator - a comparator is a device that compares two voltages and switches its output to indicate which is larger. In repsect of the 16F628A it is described in section 10 of the datasheet.
 
what is a comperater module that has analog input. (sorry for my dumb question)

hi
This code is a simple demo of the 628A comparators, it will run Oshonsoft

Its been copied from here.
https://www.electro-tech-online.com/threads/code-snippets-for-the-oshonsoft-basic-compiler.112540/

27Nov2010 for Oshonsoft IDE
'PIC 16F628/A COMPARATOR DEMO.

'Demo mode of comparator set for 4 analog channel inputs PA0.1.2.3
'displays the greater than/ less than Vref states of CMCON.7 and .6
''
'During tests, the comparision switch over is approx 5 to 10mV
E

Code:
'for Sim only
Define SIMULATION_WAITMS_VALUE = 1
 
Dim temp1 As Word
Dim vref1 As Word
Dim vrhi As Word
Dim vrlo As Word
 
'LCD assignments
Define LCD_LINES = 4
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
 
'make AN0,,1,2,3 as Inputs
TRISA = %00001111
 
TRISB = %00000000  'outputs
 
'comparator settings
CMCON.C2OUT = 0
CMCON.C1OUT = 0
CMCON.C2INV = 1
CMCON.C1INV = 1
CMCON.CIS = 0  'comparator selection PA.0/1 to PA.3/2
 
CMCON.CM2 = 0  'mode set for internal Vref connected
CMCON.CM1 = 1
CMCON.CM0 = 0
 
'Vref settings
VRCON.VREN = 1
VRCON.VROE = 0
 
VRCON.VRR = 0  'select Vref low=1 or Vref high =0
VRCON.VR3 = 1  'Vref 2^3 bit
VRCON.VR2 = 1
VRCON.VR1 = 1
VRCON.VR0 = 1  'Vref 2^0 bit
 
Lcdinit
 
'this section converts the binary to decimal value of the Vref settings
'as selected by Vr3,2,1,0 , decimal 0 thru 15
If VRCON.VR3 = 1 Then
temp1 = 8
Endif
If VRCON.VR2 = 1 Then
temp1 = temp1 + 4
Endif
If VRCON.VR1 = 1 Then
temp1 = temp1 + 2
Endif
If VRCON.VR0 = 1 Then
temp1 = temp1 + 1
Endif
 
'* 1000 to allow for lack of decimal fractions
temp1 = temp1 * 1000
 
'test if in Low or High range of Vref options
If VRCON.VRR = 1 Then  'low range
temp1 = (temp1 / 24) * 5
vrhi = temp1 / 1000
vrlo = (temp1 - (vrhi * 1000)) / 10
Else  'high range
temp1 = 1250 + ((temp1 / 32) * 5)
vrhi = temp1 / 1000
vrlo = (temp1 - (vrhi * 1000)) / 10
Endif
 
'show on LCD line 1
Lcdout "Vref= ", #vrhi, "." #vrlo
 
'above Vref value displayed once only
 
 
main:
 
CMCON.CIS = 0
Lcdcmdout LcdLine3Home
 
'test for IF PORTA.0 is  > or < than Vref, display result
If CMCON.6 = 1 Then
Lcdout "A.0>Vr"
Else
Lcdout "A.0<Vr"
Endif
 
Lcdcmdout LcdLine3Pos(10)
 
'test for IF PORTA.1 is  > or < than Vref
If CMCON.7 = 1 Then
Lcdout "A.1>Vr"
Else
Lcdout "A.1<Vr"
Endif
 
'switch from PA.0 and PA.1 to  PA.3 and PA.2 analog inputs
CMCON.CIS = 1
 
'repeat the Vref for PA.3 and PA.2 , display result
Lcdcmdout LcdLine4Home
If CMCON.7 = 1 Then
Lcdout "A.2>Vr"
Else
Lcdout "A.2<Vr"
Endif
 
Lcdcmdout LcdLine4Pos(10)
If CMCON.6 = 1 Then
Lcdout "A.3>Vr"
Else
Lcdout "A.3<Vr"
Endif
 
Goto main
 
Thank you very much, I got it. It's a analog Comperator instead of ADC

hi
There are ways of using the 16F628A as an A2D.

Its a Resistor/Capacitor discharge method that times the discharge of the capacitor in order to determine the input voltage.

I do not have a code example, but it has been discussed on these Forums.

E.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top