View previous topic :: View next topic |
Author |
Message |
bruce
Joined: 29 Jan 2008 Posts: 3
|
Comparator output always low |
Posted: Tue Jan 29, 2008 3:17 pm |
|
|
I am using the PCWH 4.065 to program a PIC18LF2620. I am using the comparator and when I read the comparator register CMCON (bit 6) C1OUT I can see it changing state from 1 to 0 to 1 etc… but when I measure Pin 6 C1OUT, it always reads zero volts.
I am using fast I/O with set_tris and have the pin configured as an output. I can toggle the output with output_toggle(PIN_A4) - just to test the pin – and I can measure pin 6 with a DVM and see it changing state. I have these other setups:
port_b_pullups(TRUE);
setup_adc_ports(AN0_TO_AN4|VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64|ADC_TAD_MUL_20);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(0x8F); //enabled, external, noSync
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_comparator(A0_VR_A1_VR|CP1_INVERT);
setup_vref(VREF_HIGH|VREF_COMP|6); //level
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
SET_TRIS_A( 239 ); //set port direction, 1=input (239) 0xef
SET_TRIS_B( 193 ); //set port direction, 1=input (193) 0xc1
SET_TRIS_C( 219 ); //set port direction, 1=input (195) 0xdb
OUTPUT_A(0);
OUTPUT_B(32);
OUTPUT_C(36);
CCS tech support has been looking at this for about a week, and they think that it could be a device header file issue. However, I was wondering… Has anyone here seen this “pin 6 is always low” problem before and solved it?
Thanks,
Bruce |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 30, 2008 5:38 am |
|
|
Comparator mode 6 doesn't connect the output of a comparator to
pin RA4. Only modes 1, 3, and 5 do so.
Look at the schematics of the comparator modes, in this figure in
the 18F2620 data sheet:
Quote: | FIGURE 20-1: COMPARATOR I/O OPERATING MODES |
|
|
![](templates/subSilver/images/spacer.gif) |
bruce
Joined: 29 Jan 2008 Posts: 3
|
Thanks |
Posted: Wed Jan 30, 2008 8:05 am |
|
|
Wow, I didn’t notice that. I had a suspicion I was doing something wrong and it wasn’t the compiler because this is the first time I have used the comparator… I am so glad I tried this forum.
I want to use the CVref feature (only available in mode 6) so it looks like I have to monitor the CMCON register and output the state of the C1OUT bit using output_bit via poll or interrupt.
Thanks,
Bruce |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jan 30, 2008 8:46 am |
|
|
Or, if you can afford the pins, use mode 5, and connect RA2 to RA3. Program the comparator reference to give an output on RA2, and 'voila'.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
bruce
Joined: 29 Jan 2008 Posts: 3
|
|
Posted: Wed Jan 30, 2008 2:34 pm |
|
|
Yes, that method uses too many pins. I only need one comparator. I could use mode 1, but the final blow to that method is that I am using Vref (needs to be 3.0V, Vdd is not reliable) for the ADC and the Comparator Voltage Reference Module.
Thanks anyway…
Bruce |
|
![](templates/subSilver/images/spacer.gif) |
|