View previous topic :: View next topic |
Author |
Message |
umarkhan
Joined: 09 Dec 2014 Posts: 7
|
dspic33 comparator |
Posted: Tue Dec 09, 2014 10:48 am |
|
|
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: 19538
|
|
Posted: Tue Dec 09, 2014 3:13 pm |
|
|
You are not telling the comparator to output on the pin. This is the COMP_OUTPUT setting. |
|
|
umarkhan
Joined: 09 Dec 2014 Posts: 7
|
|
Posted: Tue Dec 09, 2014 5:09 pm |
|
|
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: 19538
|
|
Posted: Wed Dec 10, 2014 9:54 am |
|
|
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
|
It works :) |
Posted: Wed Dec 24, 2014 5:14 am |
|
|
Thanks Ttelmah for the last post, this really cleared things up and now it works |
|
|
|