|
|
View previous topic :: View next topic |
Author |
Message |
SSURESHREDDY
Joined: 10 Aug 2013 Posts: 13 Location: bangalore
|
Comparator is not working |
Posted: Mon Aug 12, 2013 11:14 pm |
|
|
Hi all,
I need to use one built in comparator in PIC16F1824. Before I never used internal comparator. I read the data sheet and header file clearly, can anybody explain how can I set the comparator ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Aug 13, 2013 12:30 am |
|
|
Start with ex_comp.c
Your comparator is a 'double' version of the one in the 675, with more programmable inputs etc.. This though shows the 'starting point'.
Then look at some of the Microchip application notes. 41215c, has a lot of 'tips and tricks' for the comparator, which in themselves show the sort of things that can be done.
Then see if you can program a short program to have the comparator switch at a particular voltage.
If it works, smile, and give yourself a reward, if it doesn't, come back with the program, and say what it is doing, and we can try to guide you.
The big question is what you actually want to 'do' with the comparator.
Just like most of the peripherals on the PIC, though the core is simple (a amplifier that will drive it's output high or low, when one input has a higher voltage than the other), there are thousands of possible setups. You can synchronise the output with a particular clock. You can have it go high or low. You can select four different sources for each input. You can even link it's output to the PWM. You need to aim at something specific to start....
Best Wishes |
|
|
koyobearing
Joined: 13 Aug 2013 Posts: 1
|
it very useful |
Posted: Tue Aug 13, 2013 2:57 am |
|
|
Thank you for sharing with us his views, I find it very useful, thank you.If necessary, you can contact me.This is my website:spherical roller bearing |
|
|
SSURESHREDDY
Joined: 10 Aug 2013 Posts: 13 Location: bangalore
|
|
Posted: Tue Aug 13, 2013 5:12 am |
|
|
Thank you for all, actually my idea is to comparator output has to link with TIMER1, when ever output comes high timer1 will enable otherwise timer1 disable only. That Corresponding bit selections are given below,
I am confusing to set these all the bit in CCS C language. Can any body explain me how can we set.
// Configure Comparator 1. Used for the DATA input. DATA input comp'd to FVR.
C1NCH1 = 1;
C1NCH0 = 0; // Negative input is C12IN2- (pin 8).
C1PCH1 = 1;
C1PCH0 = 0; // Positive input is FVR.
C1POL = 1; // Polarity inverted (output high when C12IN2- > FVR).
#ifdef DEBUG
C1PCH1 = 0;
C1PCH0 = 0; // Positive input is C1IN+ (RA0).
C1POL = 1; // Polarity inverted, output high when C12IN2 > C1IN+ (RC2 > RA0)
#endif
C1SYNC = 1; // Output not sync'd to T1CLK.
C1OE = 0; // Output not available on C1OUT pin.
C1SP = 1; // Normal speed/power mode.
C1HYS = 1; // Hysterisis enabled (45mV typical).
C1ON = 1; // Comparator 1 on.
// Configure Timer1
TMR1 = MS_8; // Pre-load Timer1 to overflow after a count of 8000 (8ms).
TMR1CS1 = 0;
TMR1CS0 = 1; // Timer1 clock is system clock Fosc (4 MHz).
T1CKPS1 = 1;
T1CKPS0 = 0; // Timer1 clock prescaler is 1:4 (giving a clock rate of 1MHz).
T1GSS1 = 1;
T1GSS0 = 0; // Timer1 gate source is Comparator 1 Output SYNCC1OUT.
T1GPOL = 1; // Timer1 gate is active high (Timer1 counts when gate is high).
T1GSPM = 1; // Gate Single Pulse Mode.
TMR1GE = 1; // Counting controlled by gate function.
T1GGO = 1; // Timer1 Gate Go.
// Configure Fixed Voltage Reference (FVR). FVR is an input to Comparator 1.
CDAFVR1 = 1;
CDAFVR0 = 0; // Reference set to 2.048 volts.
FVREN = 1; // Fixed Voltage Reference enabled.
// Configure PWM's
PR2 = PR4 = PR6 = 0xFF; // Period registers.
// Configure interrupts
PEIE = 1; // Peripheral interrupts enabled.
TMR1IF = 0; // Clear Timer1 interrupt flag.
TMR1IE = 1; // Timer1 interrupts enabled.
TMR1GIF = 0; // Clear Timer1 gate interrupt flag.
TMR1GIE = 1; // Enable Timer1 gate interrupts.
TMR1ON = 1; // Timer1 on (only when gated by Comp1 output).
nBOR = 1; |
|
|
|
|
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
|