View previous topic :: View next topic |
Author |
Message |
denis_11
Joined: 13 Jul 2010 Posts: 45
|
comparator on 18f14k50 |
Posted: Thu Jul 22, 2010 7:08 pm |
|
|
Hi I need to use a comparator on a 18f14k50... unfortunately I'm doing the tests but the comparator can not set it... I understand I must set the ports such as:
setup_comparator (CP1_A0_VREF), or CP2_B3_VREF and CP1_B2_VREF but I did not understand what ports refer (I suppose A0, B2 and B3, right?). But if I wanted to use as inputs such as the port of CCP1 (PIN_C0) is it possible? and to set the VREF unfortunately the function setup_vref (...); does not work... why? How I set VREF? thank all! |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Fri Jul 23, 2010 9:57 am |
|
|
nobody knows how to set the VREF for the comparator in this pic? unfortunately the compiler in the wizard is approximate to this pic... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Jul 23, 2010 10:03 am |
|
|
Show us:
1) An example of the settings you are using.
2) Explain what you want think this should do.
3) What you actually see it do.
Best Wishes |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Fri Jul 23, 2010 10:14 am |
|
|
ok .. I have to compare a fixed voltage of about 3V with input pin of the pic ... and to light a LED to pin B6 as in the code:
Code: |
#include <18F14K50.H>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOBROWNOUT //No browno BORV19
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HFOFST
#FUSES NOWRT0
#FUSES NOWRT1
#FUSES USBDIV1
#FUSES BBSIZ2K //2K words Boot Block size
#FUSES CPUDIV1
#FUSES PLLEN
#FUSES PCLKEN
#use delay(clock=48000000)
#define LED_PIN PIN_B6
void main()
{
output_low(LED_PIN); // Turn off the LED initially
setup_vref(...); // HOW I SET IT FOR THIS PIC?????? AND THE COMPARATOR??
delay_us(20);
while(1)
{
if(C1OUT == 1)
output_high(LED_PIN);
else
output_low(LED_PIN);
delay_ms(100); // Debounce time
}
} |
I can not set the dial and set the input pins of the comparator and the VREF reference ... how should I do? as output fits the C1OUT ... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 23, 2010 12:42 pm |
|
|
Quote: | Unfortunately the function setup_vref (...); does not work.
why? How I set VREF? |
It's not supported for the 18F14K50 in vs. 4.109. An email should be
sent to CCS support to tell them about this. I'll try to create a substitute
function later today. |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Fri Jul 23, 2010 1:04 pm |
|
|
ok...I am waiting to hear from you because I do not know how to solve the problem... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 23, 2010 5:14 pm |
|
|
I don't have an 18F14K50 to test, but I think the following setup_vref()
routine should work. There is an example of how to call the function
given in the program below. You still have to setup the comparator
with the setup_comparator() function. The function shown below only
sets up the Vref voltage. I wrote this with compiler vs. 4.109.
Code: |
#include <18F14K50.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP,NOPLLEN,CPUDIV1
#use delay(clock=4000000)
#define VREF_ENABLE 0x80
// Note: Use 'FALSE' as parameter to disable the Vref.
void setup_vref(int8 value)
{
#byte REFCON0 = 0xFBA
#byte REFCON1 = 0xFBB
#byte REFCON2 = 0xFBC
REFCON0 = 0; // Disable fixed Vref
REFCON1 = value & 0x80; // Enable or disable Vref
REFCON2 = value & 0x1F; // Set Vref level from 0-31 (0 to +5v)
}
//==============================================
void main()
{
// Example: Enable Vref voltage of 2.65 volts.
// Vref = 5v * (17/32) = 2.65v
setup_vref(VREF_ENABLE | 17);
// Example: Disable Vref voltage.
setup_vref(FALSE);
while(1);
} |
|
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Sat Jul 24, 2010 7:25 am |
|
|
I understand and I thank you so much for your help! else ... wondering if you saw, what were the ports for setup_comparator () function ... I did not understand what are the ports available, but the settings are these: CP1_A0_VREF, CP2_B3_VREF, CP1_B2_VREF, except inverted ports ... But if I wanted to use as inputs such as the port of CCP1 (PIN_C0) and then compare PIN_C0 with VREF is it possible? |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Sat Jul 24, 2010 5:47 pm |
|
|
ok I tested the modified firmware and does not work ... :
Code: |
#include <18F14K50.H>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOBROWNOUT //No browno BORV19
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HFOFST
#FUSES NOWRT0
#FUSES NOWRT1
#FUSES USBDIV1
#FUSES BBSIZ2K //2K words Boot Block size
#FUSES CPUDIV1
#FUSES PLLEN
#FUSES PCLKEN
#use delay(clock=48000000)
#define VREF_ENABLE 0x80
#define LED_PIN PIN_B6
void setup_vref(int8 value)
{
#byte REFCON0 = 0xFBA
#byte REFCON1 = 0xFBB
#byte REFCON2 = 0xFBC
REFCON0 = 0; // Disable fixed Vref
REFCON1 = value & 0x80; // Enable or disable Vref
REFCON2 = value & 0x1F; // Set Vref level from 0-31 (0 to +5v)
}
void main()
{
setup_comparator(CP1_B2_VREF);
setup_vref(VREF_ENABLE | 20);
output_low(LED_PIN); // Turn off the LED initially
delay_us(20);
while(1)
{
if(C1OUT || C2OUT || C3OUT)
output_high(LED_PIN);
else
output_low(LED_PIN);
delay_ms(100); // Debounce time
}
} |
I used "C1OUT | | C2OUT | | C3OUT" because I did not know which of the virtual outputs was selected ... because I did not know that CP1_B2_VREF pin was referring, I tried all the pins with the positive until the LED is illuminated (compare the positive 5v with 3v of VREF), but rather nothing ... what's wrong? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 25, 2010 5:46 pm |
|
|
What pin do you want to use for the comparator input ?
In your post, you said this:
Quote: |
I wanted to use as inputs such as the port of CCP1 (PIN_C0)
|
But in the 18F14K50, CCP1 is on Pin C5. That's why I need you to give
me the correct pin. |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Sun Jul 25, 2010 6:08 pm |
|
|
oh sorry I was confused... yes, I would compare the PIN_C5 with the internal VREF (as I've suggested) and then output as a digital outputs such as C1OUT....PIN_C5 besides, what are the other pins that I could use? I preferred or C0 or C1 or C2...are these possible? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 25, 2010 9:52 pm |
|
|
It might be, but I just looked at the ASM code created by the 18F14K50
setup_comparator() function in vs. 4.109 and it's totally screwed up.
They write the wrong values to the wrong register addresses. Also,
the constants in 18F14K50.h are wrong or incomplete. I will try to
write up a usable setup_comparator() function as a work-around on
Monday. |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Mon Jul 26, 2010 6:04 am |
|
|
ok so look to hear from you... I wonder how they overlooked the series PIC18F1XK50 because the same problems are also present with 18F13K50.... |
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Mon Jul 26, 2010 2:40 pm |
|
|
Waiting in the solution, I wrote to support CCS and they said this:
"I am Attaching two files: devices4.dat and 18F14K50.h.
These two files Should fix your issue with the settings on the comparator PIC18F14K50. You Will Notice That The New 18F14K50.H contains files to use with the new Defines setup_comparator () function. To answer your other question, the setup_vref function () does not exist, You May Be Trying to use setup_low_volt_detect () function instead. "
and they have attached the 2 files as written above ... in devices4.dat I have no idea what it is but there is only 18F14K50.h changing this:
Code: | ////////////////////////////////////////////////////////////////// COMP
// Comparator Variables: C1OUT, C2OUT
// Constants used in setup_comparator() are:
//
#define NC_NC_NC_NC 0x404
#define NC_NC 0x404
//Pick one constant for COMP1
#define CP1_A1_A0 0x4000088
#define CP1_C1_A0 0x0100089
#define CP1_C2_A0 0x020008A
#define CP1_C3_A0 0x040008B
#define CP1_A1_VREF 0x400008C
#define CP1_C1_VREF 0x010008D
#define CP1_C2_VREF 0x020008E
#define CP1_C3_VREF 0x040008F
//Optionally OR with one or both of the following
#define CP1_OUT_ON_A2 0x2000020
#define CP1_INVERT 0x0000010
#define CP1_FAST 0x0000008
//OR with one constant for COMP2
#define CP2_A1_C0 0x4008800
#define CP2_C1_C0 0x0108900
#define CP2_C2_C0 0x0208A00
#define CP2_C3_C0 0x0408B00
#define CP2_A1_VREF 0x4008C00
#define CP2_C1_VREF 0x0108D00
#define CP2_C2_VREF 0x0208E00
#define CP2_C3_VREF 0x0408F00
//Optionally OR with one or both of the following
#define CP2_OUT_ON_C0 0x0082000
#define CP2_INVERT 0x0001000
#define CP2_FAST 0x0000800
#bit C1OUT = 0xf6b.6
#bit C2OUT = 0xf6d.6 |
then VREF "does not exist" and not configurable? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 26, 2010 2:58 pm |
|
|
It doesn't exist in vs. 4.109 of the compiler. We already know that.
I posted a substitute setup_vref() function for you in an earlier post.
By the way, I don't work for CCS.
I was working on the comparator functions and I don't see where they
get the names for the options. For example, for Comparator 1, they have:
Code: |
#define CP1_A1_A0 0x4000088
#define CP1_C1_A0 0x0100089
#define CP1_C2_A0 0x020008A
#define CP1_C3_A0 0x040008B
|
But in the 18F14K50 data sheet, the comparators don't use pins A0 or A1.
They only use C0, C1, C2, C3, and C4. The two comparators share
these five pins. I have no idea where they get 'A0' and 'A1' from.
I was going to give them these names:
Code: |
#define CP1_C1_C0
#define CP1_C2_C0
#define CP1_C3_C0
#define CP1_AGND_C0
|
This is a pain to do. If CCS is going to do it for you (or they already
did it), then I'm going to stop working on it. I'm not volunteering to
do this again. I suggest that you test the new features that CCS enabled
for you, and see if they work. |
|
|
|