佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2291|回复: 7

自制家里的ALARM

[复制链接]
发表于 14-4-2013 12:24 PM | 显示全部楼层 |阅读模式
i. 你要想做什么? 你的应用是什么?
最近我家贼很多,我曾去问alarm店过,包完全部要一两千,所以决定自己做。
现在只做三个input而已。
ii. 你想要拿到什么效果

开门就会响,响不停直到关电。没battery。
iii. 你做了什么
目前我已经做到了,但门一开时,horn就会响。只是简单而已,没有什么status跟密码等等。只是要用时开电就可以。

iv. 你遇到了什么问题。

问题就是 当我关我家里随便一个switch时,注意只是在关时,我的alarm会自己triggle,意识就会响。比如关十次会自己triggle3次这样。我想是noise的问题,所以我加capacitor 1000uf 下去在 input 7805.会比较好点,但有时还是会。
我做三个input用magnetic switch,wire长度是 9, 14和 7meter等等。
v. 你用什么MCU?
PIC16f877a
放vi. 你用什么语言? ASM /C/PICBasic/Keil?Compiler 版本?

C
vii. 有源码吗? 如是抄来的请注明出处, 请放链接。
viii. 有电路图吗?


跟普通我们学的一样,我用LED来但做output。button当做input。
Uploaded with ImageShack.us
ix. 你google 了吗? 你的搜索关键字是什么?
x. 有照片证明你做的东西吗?还是只是概念性的空谈?



Uploaded with ImageShack.us
本帖最后由 note2 于 14-4-2013 12:27 PM 编辑

回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 14-4-2013 12:29 PM | 显示全部楼层
其实我目的是要怎样solve第四个问题而已。。。
回复

使用道具 举报

发表于 15-4-2013 04:05 PM | 显示全部楼层
你跟我遇到问题也是一样了。。。
回复

使用道具 举报

发表于 15-4-2013 06:39 PM | 显示全部楼层
note2 发表于 14-4-2013 12:29 PM
其实我目的是要怎样solve第四个问题而已。。。

两种方法:

1. 硬体debouncing




2. 软体debouncing
参考: http://www.kennethkuhn.com/electronics/debounce.c

  1. /******************************************************************************
  2. debounce.c
  3. written by Kenneth A. Kuhn
  4. version 1.00

  5. This is an algorithm that debounces or removes random or spurious
  6. transistions of a digital signal read as an input by a computer.  This is
  7. particularly applicable when the input is from a mechanical contact.  An
  8. integrator is used to perform a time hysterisis so that the signal must
  9. persistantly be in a logical state (0 or 1) in order for the output to change
  10. to that state.  Random transitions of the input will not affect the output
  11. except in the rare case where statistical clustering is longer than the
  12. specified integration time.

  13. The following example illustrates how this algorithm works.  The sequence
  14. labeled, real signal, represents the real intended signal with no noise.  The
  15. sequence labeled, corrupted, has significant random transitions added to the
  16. real signal.  The sequence labled, integrator, represents the algorithm
  17. integrator which is constrained to be between 0 and 3.  The sequence labeled,
  18. output, only makes a transition when the integrator reaches either 0 or 3.  
  19. Note that the output signal lags the input signal by the integration time but
  20. is free of spurious transitions.

  21. real signal 0000111111110000000111111100000000011111111110000000000111111100000
  22. corrupted   0100111011011001000011011010001001011100101111000100010111011100010
  23. integrator  0100123233233212100012123232101001012321212333210100010123233321010
  24. output      0000001111111111100000001111100000000111111111110000000001111111000

  25. I have been using this algorithm for years and I show it here as a code
  26. fragment in C.  The algorithm has been around for many years but does not seem
  27. to be widely known.  Once in a rare while it is published in a tech note.  It
  28. is notable that the algorithm uses integration as opposed to edge logic
  29. (differentiation).  It is the integration that makes this algorithm so robust
  30. in the presence of noise.
  31. ******************************************************************************/

  32. /* The following parameters tune the algorithm to fit the particular
  33. application.  The example numbers are for a case where a computer samples a
  34. mechanical contact 10 times a second and a half-second integration time is
  35. used to remove bounce.  Note: DEBOUNCE_TIME is in seconds and SAMPLE_FREQUENCY
  36. is in Hertz */

  37. #define DEBOUNCE_TIME                0.3
  38. #define SAMPLE_FREQUENCY        10
  39. #define MAXIMUM                        (DEBOUNCE_TIME * SAMPLE_FREQUENCY)

  40. /* These are the variables used */
  41. unsigned int input;       /* 0 or 1 depending on the input signal */
  42. unsigned int integrator;  /* Will range from 0 to the specified MAXIMUM */
  43. unsigned int output;      /* Cleaned-up version of the input signal */


  44. /* Step 1: Update the integrator based on the input signal.  Note that the
  45. integrator follows the input, decreasing or increasing towards the limits as
  46. determined by the input state (0 or 1). */

  47.   if (input == 0)
  48.     {
  49.     if (integrator > 0)
  50.       integrator--;
  51.     }
  52.   else if (integrator < MAXIMUM)
  53.     integrator++;

  54. /* Step 2: Update the output state based on the integrator.  Note that the
  55. output will only change states if the integrator has reached a limit, either
  56. 0 or MAXIMUM. */

  57.   if (integrator == 0)
  58.     output = 0;
  59.   else if (integrator >= MAXIMUM)
  60.     {
  61.     output = 1;
  62.     integrator = MAXIMUM;  /* defensive code if integrator got corrupted */
  63.     }

  64. /********************************************************* End of debounce.c */
复制代码
回复

使用道具 举报

 楼主| 发表于 15-4-2013 11:19 PM | 显示全部楼层
pic 发表于 15-4-2013 06:39 PM
两种方法:

1. 硬体debouncing

第一个方法我已经试过了,有比较好点,但有时还是有,我想可能电容器值不够吧!但我又不懂该放多少?

至于第二个方法,我是明白。但如果要结合我的程序,要点时间。因为
  • if (input == 0)
  •     {
  •     if (integrator > 0)
  •       integrator--;
  •     }
  •   else if (integrator < MAXIMUM)
  •     integrator++;

过后我懂要怎样执行我的程序,意识triggle。对不起我programming不是很好。。。 本帖最后由 note2 于 15-4-2013 11:24 PM 编辑

回复

使用道具 举报

 楼主| 发表于 15-4-2013 11:21 PM | 显示全部楼层
wilson16 发表于 15-4-2013 04:05 PM
你跟我遇到问题也是一样了。。。

哦,那你的问题是怎样解决呢?
回复

使用道具 举报

Follow Us
发表于 16-4-2013 11:18 AM | 显示全部楼层
note2 发表于 15-4-2013 11:19 PM
第一个方法我已经试过了,有比较好点,但有时还是有,我想可能电容器值不够吧!但我又不懂该放多少?

...

那个code snippet 是给你参考, 重点是明白原理。

我也是用类似的code, 但是, 我读取input 是每50mS 读一次。
你可以在timer interrupt 里面, 当50mS 后才去读input。 其他时间不去读的。。
连续几次的读取,(可能200mS 或更长) 如果是结果是一致的, 那个输入值才被确定。

另外, 你没有说你用什么感应器, 你的感应器的输出信号有多快? 是什么类型的输出?续电器干接点?
这些要先知道,才能继续建议。

回复

使用道具 举报

 楼主| 发表于 3-6-2013 11:45 AM | 显示全部楼层
pic 发表于 16-4-2013 11:18 AM
那个code snippet 是给你参考, 重点是明白原理。

我也是用类似的code, 但是, 我读取input 是每50mS ...

对不起最近近刚忙完,我用的是以下的:

我是用active low triggle。

本帖最后由 note2 于 3-6-2013 11:49 AM 编辑

回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 17-4-2024 06:44 AM , Processed in 0.120992 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表