comparators
- NOPROBLEM48
- Posts: 30
- Joined: Tue Nov 18, 2008 11:18 am
- Contact:
comparators
Tell please how it is possible to include the analysis of a condition of comparators which are present at some microprocessors in algorithm?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: comparators
Hello
Which PICmicro are you using and what kind of functionality do you require?
Which PICmicro are you using and what kind of functionality do you require?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- NOPROBLEM48
- Posts: 30
- Joined: Tue Nov 18, 2008 11:18 am
- Contact:
Re: comparators
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?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: comparators
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- NOPROBLEM48
- Posts: 30
- Joined: Tue Nov 18, 2008 11:18 am
- Contact:
Re: comparators
Thank you very much. I suspected, that it becomes in a similar way. Your explanation will add understanding!