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.

Using comparator pins in picbasic?

Status
Not open for further replies.

MarkK

New Member
I am trying to use IR detectors (as used in mice) as positioning sensors (by counting holes) .

I am wondering on the simplest way to interface them to a PIC since the "low" voltage is somewhat higher than logic low voltage.

Any advice on using the onboard voltage comparators (16F628 and 877A) in Pic Basic Pro v2.44 would also be greatly appreciated.

Mark K.
 
MarkK said:
I am trying to use IR detectors (as used in mice) as positioning sensors (by counting holes) .

I am wondering on the simplest way to interface them to a PIC since the "low" voltage is somewhat higher than logic low voltage.

Any advice on using the onboard voltage comparators (16F628 and 877A) in Pic Basic Pro v2.44 would also be greatly appreciated.

Mark K.


Problem solved by careful resistor selection.

I would still like to know how one can use the comparators through picbasic though, if any nice person has a sample bit of code.....

M.K.
 
This is the example always given:

Code:
' PicBasic Pro Compiler 2.42, 16F877A, 
' PicBasic Pro program to demonstrate the setup and use of analog comparators.
' This program will not compile for the 16F877, as it has no comparators.  You
' must use the 16F877A, or another PICmicro MCU with comparators.  Inputs are
' analog voltages on RA0 and RA3.  The program will compare the voltages and
' tell you which is greater.  
a

C1OUT VAR CMCON.6       ' Alias C1OUT to output bit in CMCON

ADCON1 = 7                      ' Make all PORTA and PORTE pins digital
CMCON = 2                       ' Set comparators to mode 010 (see datasheet)

Low PORTE.2                     ' Set LCD to write mode
Pause 150                       ' Pause to let LCD power up

Loop:

        If C1OUT Then   ' Check comparator output
        
                ' Display if C1OUT = 1
                LCDOut $fe,1, "C1OUT = 1"
                LCDOut $fe,$C0, "PORTA.3 GREATER"
        Else
                
                ' Display if C1OUT = 0
                LCDOut $fe,1, "C1OUT = 0"
                LCDOut $fe,$C0, "PORTA.0 GREATER"
                
        End If
        
        Pause 100               ' Pause 100mS to reduce LCD flicker
        
GoTo loop                       ' Do it forever

:!: Not my code, I am just the messanger :wink:
 
MarkK said:
Problem solved by careful resistor selection.

I would still like to know how one can use the comparators through picbasic though, if any nice person has a sample bit of code.....

M.K.

I use basic from oshonsoft.

My code is:

Code:
CMCON = %00000101		'set up internal comparator

If CMCON = %10000101 Then	'if signal is greater than reference procede



The first line sets up and enables the comparator module on my pic16f628, the second line tests the value of the comparator (ie if the signal voltage is higher than the reference voltage)
 
ivancho said:
This is the example always given:

Code:
' PicBasic Pro Compiler 2.42, 16F877A, 
' PicBasic Pro program to demonstrate the setup and use of analog comparators.
' This program will not compile for the 16F877, as it has no comparators.  You
' must use the 16F877A, or another PICmicro MCU with comparators.  Inputs are
' analog voltages on RA0 and RA3.  The program will compare the voltages and
' tell you which is greater.  
a

C1OUT VAR CMCON.6       ' Alias C1OUT to output bit in CMCON

ADCON1 = 7                      ' Make all PORTA and PORTE pins digital
CMCON = 2                       ' Set comparators to mode 010 (see datasheet)

Low PORTE.2                     ' Set LCD to write mode
Pause 150                       ' Pause to let LCD power up

Loop:

        If C1OUT Then   ' Check comparator output
        
                ' Display if C1OUT = 1
                LCDOut $fe,1, "C1OUT = 1"
                LCDOut $fe,$C0, "PORTA.3 GREATER"
        Else
                
                ' Display if C1OUT = 0
                LCDOut $fe,1, "C1OUT = 0"
                LCDOut $fe,$C0, "PORTA.0 GREATER"
                
        End If
        
        Pause 100               ' Pause 100mS to reduce LCD flicker
        
GoTo loop                       ' Do it forever

:!: Not my code, I am just the messanger :wink:

Many thanks for messenging!
Mark
 
2camjohn said:
MarkK said:
Problem solved by careful resistor selection.

I would still like to know how one can use the comparators through picbasic though, if any nice person has a sample bit of code.....

M.K.

I use basic from oshonsoft.

My code is:

Code:
CMCON = %00000101		'set up internal comparator

If CMCON = %10000101 Then	'if signal is greater than reference procede



The first line sets up and enables the comparator module on my pic16f628, the second line tests the value of the comparator (ie if the signal voltage is higher than the reference voltage)

Great, looks easy enough! thanks!
Mark K.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top