Page 1 of 1

Custom Interrupt for Comparator

Posted: Fri Feb 26, 2016 5:02 pm
by Dave Squibb
Hello,

I am trying to get the Comparator to work in Flowcode 6 on a PIC16F627A. I want to use the single comparator mode (CMCON <2:0> = 101) and trigger a custom interrupt when the Comparator switches.
I have based the Custom Interrupt code on the code from Benj here:

http://www.flowcode.co.uk/mmforums/viewt ... =23&t=4780

I am using the VRef module on RA2 with the input on RA1. I have measured 2.5V on RA2 as expected.
Varying the voltage on RA1 above and below this doesn't light the LED on RB7.

Can anyone spot what I have done wrong please?

Thanks, Dave.

Re: Custom Interrupt for Comparator

Posted: Mon Feb 29, 2016 11:55 am
by Benj
Hi Dave,

It looks to me like it should be working. However I did spot this line in the datasheet.
The internal reference signal is used when the comparators are in mode CM<2:0>=010 (Figure 10-1). In this mode, the internal voltage reference is applied to the VIN+ pin of both comparators.
So you might have to use cmcon = 2 rather than cmcon = 5 like you have now.

Re: Custom Interrupt for Comparator

Posted: Mon Feb 29, 2016 3:53 pm
by Dave Squibb
Thanks for that Benj. Despite that it DOES still work with CMCON = 5.

The problem was the test line FCV_C2 = test_bit(cmcon, C2OUT);

That doesn't work but FCV_C2 = cmcon.C2OUT; does.

Is that something that has changed between the original V2/V3 post and V6?

Re: Custom Interrupt for Comparator

Posted: Sat Jul 30, 2016 12:03 pm
by skquah
Hello... Benj, Dave Squibb, and all
1) I am just starting and keen to learn about how to implement flow-code to this comparator 16F627A/16F628A topic..
2) I have downloaded the attached flow-code file and start as a beginner to figure out on Dave Squibb problem and solution
from Benj, and I have search thru' the data sheet 16F627A on the 10.1 comparator module configuration to understand
the topic discussion.. But I still in doubt and could not get the downloaded flow-code running when I start the simulation run..
3) Here is my question :-
i) Can someone help me to update/ correct the flow-code codes and test for proper functioning then upload new file for my learning..
ii) How to do testing in the start run mode as there is no ADC component knob connected in the view panel. I only see there is
one output led connected to RB7.. Seriously, I am a novice and I need help to get started on this comparator topic..
4) Many thanks, should someone educates me and I appreciate that... [email-deleted]

Re: Custom Interrupt for Comparator

Posted: Sat Jul 30, 2016 12:59 pm
by kersing
But I still in doubt and could not get the downloaded flow-code running when I start the simulation run..
This flowchart contains C code icons, C code icons do not simulate, so you will not be able to simulate this flowchart. As the comparator requires C code there are no interface components on the panels.
The only way to try this is on hardware.

Re: Custom Interrupt for Comparator

Posted: Sun Jul 31, 2016 4:19 am
by skquah
Thanks, Kersing