Comparator tips and tricks from Microchip

edmunds

Senior Member
Dear all,

While browsing for solutions, I stumbled across this document from Microchip. I find it so interesting, I dare to post it here for general information. Hope you find the solutions proposed useful, too.

Edmunds
 

kranenborg

Senior Member
Indeed this document is very useful, and the comparator functionality is available fully to the PICAXE platform. When combining the comparators with the DACs and SR-Latch available on all M2 variants, even more is possible!

This is because although only the PICAXE-X2 variants have explicit BASIC commands for the use of the comparators, the M2 variants have comparators as well (even the 08M2 has one) with the same functionality. By initializing the appropriate SFRs they can be used on any M2. I presume the reason for not having M2-Basic commands supporting the comparators is the limited Flash memory of the M2 series available to the BASIC-interpreter as compared to the X2 series, thereby limiting the number of BASIC commands that can be implemented. Yet, the chip silicon supports the modules completely, so they can still be configured and used through the SFRs.

The following two links show the use of a comparator combined with the DAC and SR-Latch modules on an M2:

1: Educational, simple example of using two comparators on an 18M2 (one programmed to have inverting output, the other non-inverting output) to drive two LEDS. The (-) inputs of both comparators are connected to a single potentiometer, the (+) inputs are connected to the internal DAC that is programmed (for this example) at 0.5Vcc output voltage. As a consequence the LEDs change alternately on/off at the programmed DAC voltage level when turning the potentiometer: http://www.picaxeforum.co.uk/showthread.php?17654-Use-of-Comparators-in-the-PICAXE-18M2

2: Extension of the previous approach to implement a fast spike detector on an 08M2, using the comparator - DAC combination as a programmable noise canceler which sets the M2 latch (using SRLATCH). The latch is used as a memory bit to immediately catch the spike event (the latch set by a comparator output is another great feature that formally is not available for M2, but in reality is, as shown by the code example!) as a way to be able to detect very short/fast events: http://www.picaxeforum.co.uk/showthread.php?21422&p=207723&viewfull=1#post207723
(PS: see also the discussions in the earlier posts of that same thread, as they reveal the possibilities/limitations of the modules for certain M2 variants and the effects of initializations done by the PICAXE firmware)
The hardware configuration for this 08M2 fast spike detector example is shown here below (notice that leg numbers, not pin numbers have been used):

SpikeDetector.jpg


As one can see, the PICAXE concept in combination with the Forum support is unbeatable. Furthermore, I regard the M2 series no less powerful than the X2 series, as shown by the examples here.

More PICAXE code examples that may be useful in general can be found here: http://www.kranenborg.org/electronics/10-picaxe-and-zbasic-code-contributions

Best regards,
Jurjen
http://www.kranenborg.org/electronics
 
Last edited:
Top