查看: 2680|回复: 7
|
自制家里的ALARM
[复制链接]
|
|
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 编辑
|
|
|
|
|
|
|
|

楼主 |
发表于 14-4-2013 12:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 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
- /******************************************************************************
- debounce.c
- written by Kenneth A. Kuhn
- version 1.00
- This is an algorithm that debounces or removes random or spurious
- transistions of a digital signal read as an input by a computer. This is
- particularly applicable when the input is from a mechanical contact. An
- integrator is used to perform a time hysterisis so that the signal must
- persistantly be in a logical state (0 or 1) in order for the output to change
- to that state. Random transitions of the input will not affect the output
- except in the rare case where statistical clustering is longer than the
- specified integration time.
- The following example illustrates how this algorithm works. The sequence
- labeled, real signal, represents the real intended signal with no noise. The
- sequence labeled, corrupted, has significant random transitions added to the
- real signal. The sequence labled, integrator, represents the algorithm
- integrator which is constrained to be between 0 and 3. The sequence labeled,
- output, only makes a transition when the integrator reaches either 0 or 3.
- Note that the output signal lags the input signal by the integration time but
- is free of spurious transitions.
-
- real signal 0000111111110000000111111100000000011111111110000000000111111100000
- corrupted 0100111011011001000011011010001001011100101111000100010111011100010
- integrator 0100123233233212100012123232101001012321212333210100010123233321010
- output 0000001111111111100000001111100000000111111111110000000001111111000
- I have been using this algorithm for years and I show it here as a code
- fragment in C. The algorithm has been around for many years but does not seem
- to be widely known. Once in a rare while it is published in a tech note. It
- is notable that the algorithm uses integration as opposed to edge logic
- (differentiation). It is the integration that makes this algorithm so robust
- in the presence of noise.
- ******************************************************************************/
- /* The following parameters tune the algorithm to fit the particular
- application. The example numbers are for a case where a computer samples a
- mechanical contact 10 times a second and a half-second integration time is
- used to remove bounce. Note: DEBOUNCE_TIME is in seconds and SAMPLE_FREQUENCY
- is in Hertz */
- #define DEBOUNCE_TIME 0.3
- #define SAMPLE_FREQUENCY 10
- #define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
- /* These are the variables used */
- unsigned int input; /* 0 or 1 depending on the input signal */
- unsigned int integrator; /* Will range from 0 to the specified MAXIMUM */
- unsigned int output; /* Cleaned-up version of the input signal */
- /* Step 1: Update the integrator based on the input signal. Note that the
- integrator follows the input, decreasing or increasing towards the limits as
- determined by the input state (0 or 1). */
- if (input == 0)
- {
- if (integrator > 0)
- integrator--;
- }
- else if (integrator < MAXIMUM)
- integrator++;
- /* Step 2: Update the output state based on the integrator. Note that the
- output will only change states if the integrator has reached a limit, either
- 0 or MAXIMUM. */
- if (integrator == 0)
- output = 0;
- else if (integrator >= MAXIMUM)
- {
- output = 1;
- integrator = MAXIMUM; /* defensive code if integrator got corrupted */
- }
- /********************************************************* 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 
你跟我遇到问题也是一样了。。。
哦,那你的问题是怎样解决呢?
|
|
|
|
|
|
|
|
发表于 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 编辑
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|