项目作者: binarymaker

项目描述 :
Microcontroller digital hysteresis comparator
高级语言: C
项目地址: git://github.com/binarymaker/hysteresis-comparator.git
创建时间: 2019-05-31T06:44:53Z
项目社区:https://github.com/binarymaker/hysteresis-comparator

开源协议:

下载


Hysteresis comparator

Microcontroller Digital signal hysteresis comparator

Library files

Concept

  1. /\/\ , ,
  2. signal /\/\ /\/\ /\/\ || /\/\
  3. threshold->-/\/\------------/\/\-------------/\/\-----||-----/\/\--
  4. ^ ^ /\/\ /\/\ ^ ||
  5. | | /\/\ | ||
  6. Noise make error in compare --------+ ^^-spike
  7. ____________ _____ _____
  8. caparator |||| ||||_____________|||| || ||||__
  9. output
  10. ______________ _______________
  11. hysteresis ______| |________________| |_
  12. comparetor
  13. output

Code usage

  1. /* Include library */
  2. #include "hysteresis.h"
  3. /* Hysteresis comparator objects */
  4. hysteresis_t hy_comp_1;
  5. hysteresis_t hy_comp_2;
  6. void main()
  7. {
  8. /* Initialization of hysteresis comparator */
  9. hysteresis_create(&hy_comp_1, 30, 100); /* 30 - threshold value, 100 - time delay in ms*/
  10. hysteresis_create(&hy_comp_2, 50, 150); /* 50 - threshold value, 150 - time delay in ms*/
  11. while(1)
  12. {
  13. signal = signal_source(); /* signal source function may ADC, Capture count, sensor data*/
  14. /* comparator process
  15. *
  16. * call this function maximum passible short time
  17. *
  18. * Optional: filter signal before compare
  19. */
  20. hysteresis_compare(&hy_comp_1, signal);
  21. hysteresis_compare(&hy_comp_2, signal);
  22. process_or_print = hy_comp_1.hys_state;
  23. process_or_print = hy_comp_2.hys_state;
  24. }
  25. }

Example test code

Refer this code

test output

Test parameter

  • Threshold value - 500
  • Comparator time delay - 50ms

Signal

  • channel 1 - Signal + Noise (+/- 100)
  • channel 2 - Normal comparator
  • channel 3 - Hysteresis comparator

alt text

alt text