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

dspic33 comparator

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



Joined: 09 Dec 2014
Posts: 7

View user's profile Send private message

dspic33 comparator
PostPosted: Tue Dec 09, 2014 10:48 am     Reply with quote

Hi,
I am trying to use the comparator in the dspic33ep256mu806. All I want to do is to observe the voltage at the C3IN1+ pin, and if it exceeds the internal reference voltage of 1.18V C3OUT should go high else remain low. I have tried the following code but the C3OUT always remains low. The dspic is functioning properly for other applications in which I used the ADC, controlled an LED and communicated with a pc through the serial port. So I am sure that the dspic and the supporting circuitry are ok.
Code:

#include <33EP256MU806.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#use delay(clock=80M, xtal=8M)
#define LED1      PIN_D0

//Setup uart
#pin_select U1RX=PIN_E3
#pin_select U1TX=PIN_E4
#use rs232(UART1,baud=115200,parity=N, stream=NETWORK, ERRORS)



void main()
{

    delay_ms(100);
    fprintf(NETWORK,"\n\rStarting\n\r");
   
    delay_ms(100);
   
    //Setup Comparator
   
    setup_vref(VREF_INTREF_1v18 );
    setup_comparator(CXIN3_VREF,COMP_INTR);
   
    output_high(LED1);
    delay_ms(100);
    while(C3OUT==0);
   
    fprintf(NETWORK,"Input exceeds threshold\n\r");
 }

Any clues would be very helpful.
Ttelmah



Joined: 11 Mar 2010
Posts: 19245

View user's profile Send private message

PostPosted: Tue Dec 09, 2014 3:13 pm     Reply with quote

You are not telling the comparator to output on the pin. This is the COMP_OUTPUT setting.
umarkhan



Joined: 09 Dec 2014
Posts: 7

View user's profile Send private message

PostPosted: Tue Dec 09, 2014 5:09 pm     Reply with quote

Thanks for that, will try it. Also I am not sure how to specify a particular comparator. The dspic33ep256mu806 has three. Can you please tell me how a particular one is enabled?
Ttelmah



Joined: 11 Mar 2010
Posts: 19245

View user's profile Send private message

PostPosted: Wed Dec 10, 2014 9:54 am     Reply with quote

Quote:

"The first parameter is the comparator number".

All the other parameters 'OR' together.

So

setup_comparator(1, CXIN3_VREF|COMP_INTR|COMP_OUTPUT);

Sets up comparator 1 to both output, and interrupt.
umarkhan



Joined: 09 Dec 2014
Posts: 7

View user's profile Send private message

It works :)
PostPosted: Wed Dec 24, 2014 5:14 am     Reply with quote

Thanks Ttelmah for the last post, this really cleared things up and now it works Smile
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