Schmitt Trigger characteristics of Pin C.2 on Picaxe 08M2

PhilHornby

Senior Member
As stated in this thread (and the manual), Pin C.2 on the Picaxe 08M2 is a Schmitt Trigger type and I was wondering if I could make use of it to detect a changing analogue signal.

The documentation states that a "high" will be any voltage > 0.8 * Vsupply and a "low" any voltage < 0.2 * Vsupply. For some reason, I measured rather different values in my test circuit, but I have no idea why!

Circuit:

Diagnostic.jpg


The idea is set Pin C.1 to be the inverse of that detected at C.2 - thus alternately charging and discharging the 100uF capacitor via the 10K resistor. When I look at the signals on C.1 and C.2, this is what I see:-

Diagnostic on scope.jpg

Using a 5.1V supply, the upper and lower trigger points are 2.1V & 1.87V respectively (0.41 * Vsupply & 0.37 * Vsupply). Not only do these not match the published figures they are suspiciously close together.

I tried two methods of detecting the state of Pin C.2. One was to steal some code that Hippy posted recently using the 'edge detection' logic. The other was a much more straight-forward "if PinC.2 = 1 " then "low C.1" type approach:-

Code:
#picaxe 08m2
#terminal 38400
#no_data 
#no_end
;
; SFRs
; 
; Datasheet values to Pe6 conversion
;
; eg 099h => 039h
;
;  0    9    9
;0000 1001 1001
; |   |xx|   /
;  \  / /   /
; 0011 1001/
;   3    9 
;
;Symbol OSCON = $39     ;$099 - Oscillator control


;Interrupt On Change SFRs


Symbol IOCAP = $F1      ;$391 - Capture positive edges
Symbol IOCAN = $F2      ;$392 - Capture negative edges
Symbol IOCAF = $F3      ;$393 - Capture flag



 setfreq M32


Version #1


 PokeSfr IOCAN,%00000100    ;capture negative-going transitions on C.2
 PokeSfr IOCAP,%00000100    ;capture positive-going transitions on C.2
 PokeSfr IOCAF,0                    ;say none captured so far
 
 high C.1     ;start capacitor charging
do
 PeekSfr IOCAF, b0    ;get no. of edge detections
 
 if b0 <> 0 then     ;got an edge
  toggle C.1    ;reverse charge/discharge
  pokeSfr IOCAF,0    ;clear edge detection.
 endif
loop


Version #2


do
 if PinC.2 = 1 then    ;when pin is "high",
  low C.1     ;discharge capacitor
 else      ;when "low"
  high C.1    ;charge it
 endif
loop
What is going on?
 

Technical

Technical Support
Staff member
0.8 is greater than 0.41 and 0.2 is less than 0.37, so the figures in the manual quoted are correct.

0.2 and 0.8 * Vsupply are not the schmitt trigger point, they are the guaranteed state point. They are known as VIL and VIH in the Microchip datasheets.

Any input between 0.2 and 0.8 is undefined and cannot be guaranteed to be a high or a low. However of course it still needs to be either high or low, its just Microchip do not guarantee the state unless it is definitely >0.8 or <0.2
 
Last edited:

AllyCat

Senior Member
Hi Phil,

Yes I vaguely remember a forum post some years ago that the high Schmitt input is much lower than "implied" by the data sheet. But 80% of Vdd does seem surprisingly high for a "minimum" level, so technical's interpretation that it's actually a "maximum" is presumably correct. The input clearly has some Schmitt behaviour; a normal input would have almost no hysteresis.

If you need a larger hysteresis, then there may be other methods. The "Touch" inputs are basically an oscillator similar to your configuration, with larger (and selectable) input thresholds (at least according to my interpretation of the data sheet). There are internal current sources but they can be set to a very low level, so might not affect your external circuit.

However, the internal Comparator is probably a better choice, but can be accessed only via SFR commands (and lots of browsing through the data sheet). The Comparator also has an optional, small amount of hysteresis, but I'm not convinced the difference between the "normal" and "low power" hysteresis values are as different as the data sheet suggests (from the section 31 graphs in the latest 14/20M2 base data sheet).

Alternatively, you can "make" a Schmitt inside the 08M2, using its comparator. Pin C.2 is the comparator output and C.0 the positive input (which inconveniently is the PICaxe's Serial Out). But C.1 can be the "Reference" to the "DAC", which is basically the top of an internal potentiometer (other end to ground). The "wiper" of the pot (DAC output) can be internally connected to the Comparator positive input, so linking C.1 and C.2 can give the desired positive feedback. In this case C.4 needs to be selected as the comparator negative input (i.e. Schmitt input), but another possibility is to use C.1 as the negative input and apply the positive feedback via a (high value) resistor to C.0 (internally configured to connect the pin to both the DAC "wiper" and Comparator input).

Cheers, Alan.
 

hippy

Technical Support
Staff member
The PICmicro datasheet for the 28X2 "electrical specifications" includes two graphs which shows typical schmitt trigger points for going low and high. Figures 28-81 and 28-83 in my datasheet. I have no idea why the PICmicro datasheet for the 08M2 does not have the same graphs but that is often typical of Microchip datasheets.

Test results with a 28X2 seem comparable with an 08M2, with the pin reading going low at around 1.7V and going high at around 2.1V using a 5V supply.

The Vil and Vih are shown on the graphs and appear, as Technical states, values at which it can be guaranteed the outputs inputs will have gone low or gone high, rather than specifying the actual switching points.
 
Last edited by a moderator:

PhilHornby

Senior Member
A picture's worth a thousand words...

The PICmicro datasheet for the 28X2 "electrical specifications" includes two graphs which shows typical schmitt trigger points for going low and high. Figures 28-81 and 28-83 in my datasheet.
Ah - that makes more sense. I don't know why I didn't think to look there myself :). I wonder why Microchip felt the need to add the dotted-lines to the graphs (which must equate to operation at Absolute-zero or 500°c!). I understand that logic levels have a range of values, but I naively thought that the point of adding a Schmitt trigger was to put them within a more clearly defined range.

@Allycat I don't actually need a Schmitt input for anything at the moment - I was just investigating their characteristics. I was intrigued by "Saunj's" use of a digital input to measure an analogue event in this thread ... an interrupt triggered by the state of charge of a capacitor made my mind boggle somewhat! I assumed he would have needed to configure the input pin as a Schmitt trigger - but apparently not.
 
Top