View Full Version : Request for Teensy 3 analog comparator library functions

09-04-2013, 08:03 PM
Hello Paul:
Let me start by saying I am excited about the product, I've been a Freescale person since they were Motorola and used the early 6800 series, and watched them do what I think was the first ADC on the same die as the microcontroller. Very cool stuff at the time. Also, we were coding in assembly and sometimes BASIC, and FORTH...that is until C came along; thank heaven for that!

So now you build a nice micro soldered and tested on a super small USB board with a lightning fast core and peripherals and a 13-14 (effective) bit ADC....all for under 20 bucks! So far I have 3 of them, with plans on 10 more for my prototypes, and then about 1K per year, which in the PV solar business is pretty low volume. Why not spin my own controller? Easy: For that volume it is just not worth it. 10k/yr...that is another whole potato, for that I'd design my own controller, like we did at Trace, Xantrex, Outback, and Magnum before.

I've got a good part of my application going, but I still need use a good, fast, (and did I mention) cheap comparator. Comparators are often used for motor control/inverter/charger MOSFET power sections, where you need fast overcurrent detection to keep the power devices from letting the smoke out, or for very quick and consistent AC zero crossing detection to get accurate AC RMS samples and for grid synchronization. If your inverter does not sync perfectly with the grid, this is not a good thing!!

The Teensy 3.0 has two on-die comparators - CMP0 and CMP1. Would it be possible to have a few functions that use one or both of these? It would be helpful to have the DAC reference available also. In my application, AC is scaled from about +3V to about 0.3V with the zero at 1.65V, so the comparator input reference needs an equivalent offset.

Also nice to have, but not totally necessary, would be adjustable hysteresis ( CR0[HYSTCTR] = 00-11), pin reassignment for those needing to cram in other functions, and the interrupt capability of the comparators. This last thing can be done external to the chip if there are enough extra I/O pins for the application. I think the filter function is a nice to have also, but a simple R or RC is usually all that is needed for most apps.

Thanks for reading this, and I hope you have the time and energy to do this for us analog guys!!
(offgrid engineering)
P.S. I do know that an external 20 cent comparator (maybe 35 cents for two) can be added instead. But hey....it's already on-chip now!!! Seems crazy in this world of trying to reduce waste and energy to duplicate parts, right?!

09-11-2013, 08:55 PM
I'm not sure on the netiquette of replying to your own posts, but that's never stopped me before!
So here is the circuit I ended up with:

I do realize we are all busy, and so I understand the reluctance to take on new work, and if that is the case, maybe just give us the tools or
information to access the comparator ourselves. In my earlier posts, I've documented the bug of using the comparator commands...

Now I need to get back and try to get all the functions from the ADC this chip provides!!


10-02-2014, 02:16 PM
I recognize that I am a master of bumping older threads, but this still seems highly relevant and was found as I was searching along on the topic.

Did you have any luck using the internal comparator? Also, you also seem to reference the DAC but I think that's only for the teensy 3.1, unless the DAC reference is different than the DAC i am thinking of.

It looks like you made some progress on another thread, "http://forum.pjrc.com/threads/23432-Teensy-3-0-Analog-Comparator-Interrupt" but not complete progress.

10-20-2014, 02:54 AM
I made a tiny library for Teensy 3's analog comparator. This is based on the analogComp library written by Leonardo Miliani for Atmel microcontrollers.
The library only supports primitive functions but I think the difficult part of implementation is over. And you can now easily modify it as you like. :)

Note: I only checked analogComparator1 on CMP1_IN0 (pin 23) and CMP1_IN3 (A14/DAC) for GoPro Hero 3+ Black video motion detect and it works great.

10-31-2014, 04:15 PM
Are you using your go pro camera as a motion detector? I am trying to use a camera to give some vision sensing (primarily for motion detection) to my Teensy 3.1. From what I understand, using ADC is too slow (maximum 1.2Msps on Teensy 3.1). So I am thinking to use the comparators. Just curious if you had tried it.

11-01-2014, 12:19 AM
I wrote a blog post on this subject. Please have a look at http://mewpro.cc/?p=334

Video capture is driven by interrupts generated by Teensy's analog comparator. But I don't use Teensy's DMA yet, so if you can deal with it there will be great opportunities.