Page 1 of 1
comparators
Posted: Thu Dec 18, 2008 7:59 pm
by NOPROBLEM48
Tell please how it is possible to include the analysis of a condition of comparators which are present at some microprocessors in algorithm?
Re: comparators
Posted: Fri Dec 19, 2008 9:49 am
by Benj
Hello
Which PICmicro are you using and what kind of functionality do you require?
Re: comparators
Posted: Fri Dec 19, 2008 12:09 pm
by NOPROBLEM48
All representatives of families PIC12F6XX and PIC16F6XX, and also the majority other modern PICmicro have the built in comparators. Adjustment of their configuration, interruptions from change of a condition and the alarm system about conflicts to input and output functions would be quite in style FlowCode. Now it is possible only in language C independently and for each crystal separately. Or I am mistaken?
Re: comparators
Posted: Fri Dec 19, 2008 2:36 pm
by Benj
From looking at the 16F88 datasheet there are two main registers to control the comparitor and comparitor voltage reference functions. The register's names may change or be slightly different on other devices.
To assign values to these registers in Flowcode simply use a C code block.
cmcon = 0x00;
cvrcon = 0x00;
Replace 0x00 with the hex values you require for your comparitor configuration.
You should be able to read back the comparitor results by reading the specific digital input connected to the output of the comparitor. Alternativly you can trigger interrupts when the compartior output changes. To do this you will need to set up a custom interrupt.
Enable
intcon.PEIE = 1; // Enable peripheral interrupts
intcon.GIE = 1; // Enable global interrupts
pie2.CMIE = 1; // Enable comparitor interrupts
Disable
pie2.CMIE = 0; // Disable comparitor interrupts
Handler
if (pir2 & (1 << CMIF))
{
FCM_%n(); // call selected macro
clear_bit(pir2, CMIF); // clear interrupt
}
Again this code is for the 16F88. Most other PICmicro devices may be similar but not nessicarily the same so please refer to the PICmicro datasheets for the exact settings.
Hope this helps.
Re: comparators
Posted: Fri Dec 19, 2008 3:08 pm
by NOPROBLEM48
Thank you very much. I suspected, that it becomes in a similar way. Your explanation will add understanding!