View previous topic :: View next topic |
Author |
Message |
bungee-
Joined: 27 Jun 2007 Posts: 206
|
Comparator module problem - [SOLVED] |
Posted: Wed Jul 01, 2009 2:39 pm |
|
|
Hi!
I'm trying to make an LC-meter that is similar to the one in this link: Digital LC Meter v2 But I have problems with the comparator module that don't want to oscillate.
I use PIC16F916 (first one i grab yesterday) and it has built in comparators.
Part of the code, I turn on the comparators is here:
Code: | setup_adc_ports(sAN0|sAN1|sAN2|VSS_VDD);
setup_comparator(A0_A2_A1_A2);
setup_vref(false);
#use fast_io(A)
set_tris_A(0b01001111);
|
I have LCD on port b and that is among parts for oscillator everything that is connected to the pic itself.
Any idea?
P.S.: Compiler PCD v 4.088
Last edited by bungee- on Thu Jul 02, 2009 1:10 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 01, 2009 3:54 pm |
|
|
Quote: | I use PIC16F916 (first one I grab yesterday). |
It's better to grab one that isn't a specialized PIC. Grab a general purpose
PIC. The 16F916 has a built-in segment LCD module. If you're using an
ordinary parallel-interface LCD, then you need to turn off the segmented
LCD module. Do that by putting this line of code near the start of main():
Code: | setup_lcd(LCD_DISABLED); |
Quote: |
I turn on the comparators here:
setup_comparator(A0_A2_A1_A2);
setup_vref(false);
|
He has source code that shows the comparator and vref setup:
http://ironbark.bendigo.latrobe.edu.au/~rice/lc/lc2.txt
Here's his ASM code:
Quote: | InitIO
movlw b'00000110'
movwf CMCON ; Select Comp mode
bank1
movlw b'00000000'
movwf VRCON ; Set Volt ref mode to OFF |
He's setting the comparators to mode 6. Your code sets them to mode 3.
You need a comparator setting that his similar to his. This is the closest
one for the 16F916:
Code: | setup_comparator(A0_A2_A1_A2_OUT_ON_A4_A5); |
From his schematic, it looks like he is only using the output of
comparator 1. He has a 4.7K pullup on the output of comparator 2.
He has some sort of "FET" symbol going from the output of Comparator 2
to the Vss pin (Ground). I don't know what he's doing there. So I think
only Comparator 1 is used in his design. In the 16F628, the output of
Comparator 1 goes to pin RA3. But in the 16F916, the output of Comp 1
goes to pin RA4. So you need to change the schematic.
Also, if you want to duplicate his 4.7K resistor on the output of Comp 2,
you need to put it on pin RA5. That's the Comp 2 output pin on the 16F916.
It would have been much easier if you just had a 16F628 in stock.
Quote: | #use fast_io(A)
set_tris_A(0b01001111); |
My advice is to let the compiler set the TRIS.
Vs. 4.088 is a fairly late version. The compiler probably does it correctly.
(i.e., don't use fast i/o mode, and don't put in a set_tris_a() statement). |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Wed Jul 01, 2009 6:06 pm |
|
|
Will try with another PIC. I didn't work with comparator in PIC till now. I'll report results tomorow.
Thanks for advice! |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Thu Jul 02, 2009 1:09 am |
|
|
I took PIC16F886 and in the first place there is more options for setting the comparator in the first place
Result is ... it works like a charm
Here is the actual comparator setup:
Code: | setup_comparator(CP1_A0_A3|CP2_A1_A2|CP1_OUT_ON_A4|CP2_OUT_ON_A5); |
I can use one comparator and that's enough for my project. Thank you for your hints .....
Lesson learned: Don't use specialised PIC-s unless you need that special function |
|
|
|