CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Comparator output always low

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bruce



Joined: 29 Jan 2008
Posts: 3

View user's profile Send private message

Comparator output always low
PostPosted: Tue Jan 29, 2008 3:17 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 30, 2008 5:38 am     Reply with quote

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
bruce



Joined: 29 Jan 2008
Posts: 3

View user's profile Send private message

Thanks
PostPosted: Wed Jan 30, 2008 8:05 am     Reply with quote

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
Ttelmah
Guest







PostPosted: Wed Jan 30, 2008 8:46 am     Reply with quote

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'. Smile

Best Wishes
bruce



Joined: 29 Jan 2008
Posts: 3

View user's profile Send private message

PostPosted: Wed Jan 30, 2008 2:34 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group