5iMX宗旨:分享遥控模型兴趣爱好

5iMX.com 我爱模型 玩家论坛 ——专业遥控模型和无人机玩家论坛(玩模型就上我爱模型,创始于2003年)
查看: 2999|回复: 26
打印 上一主题 下一主题

PPM接收机智能解码

[复制链接]
跳转到指定楼层
楼主
发表于 2007-7-14 22:39 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
前两天在网上找到一些用单片机解码PPM接收机的资料和程序   文章介绍说程序包括正
负波参数,  油门动作侦测, 以及讯号保留及断讯过时回正位. "正负波参数" 也就是可以
支援 JR 及 Futaba 系统,  "油门动作侦测" 防止开机
时发射机油门没有归回低位而发生危险 (包括 JR CH-1 and Futaba CH-3). "讯号保留"
為防止讯号不良或瞬间被干扰, 保留前一组完整之讯号, 也可以避免 SERVO 抖动. "断讯
过时回正位" 就是飞行安全模式, 一段时间没有讯号, 所有 SERVO 回正, 油门关到底..
...不错吧 ! PIC IC 体积又小, 线路又简单, 在他的 12C508/9 还加上一组 LED, 显示是否
工作且有接收到正常讯号
    我试着做了一个但没成功 现把程序放上来请懂的哥们看看  本人电子硬件方面还过得去
软件一窍不通啊  我用的编程器是TOP2005  单片机用过贴片12C508A  插脚12F508  12F509
是不是单片机一定要12C508或12C509呀 我查了资料12C508A比12C508容量大点其他一样啊


不会上附件 先复制ASM文件上来  HEX文件也有

;***************************************************************************
;   rxdecode.asm      Pulse Position Modulation Decoder for 4 Channel Rx
;***************************************************************************
;            Bruce Abbott   bhabbott@paradise.net.nz
;
;        for Microchip PIC 12C508, 12C509, 12F629 or 12F675.
;
;============================= Description =================================
;
; PPM DECODER:
;
; Each frame consists of 4 to 8 channels (5 to 9 pulses), followed by a sync
; gap. We only decode the first 4 channels.
;
; The width of each channel is 1 to 2mS (1.5mS when sticks centered). The
; sync gap is at least 2.5mS long, and frame length is approximately 20mS.
;
; The input signal should look something like this:-
;
;            |<------------------ 1 frame (~20mS) -------------------->|
;            |< 1~2mS >|                                 
;             _         _        _        _        _                    _
; ___________| |_______| |______| |______| |______| |__ // ____________| |____
;   sync gap     ch1       ch2      ch3      ch4       etc.  sync gap      ch1
;
; NOTE: This waveform shows positive 'shift'. If your Rx outputs negative
;       'shift', the waveform is inverted.  
;
; There is just enough time to generate four decoded outputs after receiving
; channel 4, and before the end of the sync gap.
;
; GLITCH FILTER:
;
; Each channel is averaged with the value from the previous frame, reducing
; servo jitter on weak signals. If any channel in a frame is corrupted, the
; whole frame is discarded and the last good frame is used instead.  
;
; FAILSAFE:
;
; On receiving a sufficient number of good frames we save it for failsafe.
; Then, if the signal is corrupted for too long, we output the failsafe frame
; instead of the last good frame.  
;
; THROTTLE ARMING:
;
; When entering failsafe the throttle is cut, and it will not be restarted
; until a good signal is detected AND the throttle is manually reset. This
; should prevent the situation where motor-induced RF interference causes
; the decoder to cycle in and out of failsafe repeatedly.  
;
; For this feature to work the throttle channel has to be determined. Futaba
; and Hitec tranmitters assign the throttle to channel 3. JR, Airtronics and
; GWS use channel 1.
;
; Some ESC's need to have the throttle set to maximum at startup, perhaps to
; disable the brake or to enter programming mode. Therefore, channel 1 is
; designated as throttle if it measures less than 1.3mS or more than 1.7mS at
; startup, otherwise channel 3 is assumed.
;
; The throttle channel is forced to 1.05mS during failsafe, rather than set
; to its failsafe value, in case that value was full throttle!
;
; =============================================================================
;                             Summary of Changes
;
; 2003/12/2  V0.5 - Initial release
;
; 2003/12/27 V0.6 - ASM Error if 'addwf PCL' not in page 0.
;                 - Select processor via MPLab's Device Select menu.
; 2004/1/7   V0.7 - No output until failsafe frame captured. Should now be
;                   compatible with JR/GWS transmitters (throttle on CH1).
;                    
; 2004/1/9   V0.8 - Increased range to 0.75~2.28mS, now accepts >125% throws.
;                   Resolution is slightly reduced (from 5uS to 6uS).                 
;                 - Failsafe and Hold frames now use averaged output values.
;                 - Ignore missing 4th channel (for 3 channel TX) NOT TESTED!
;
; 2004/2/15  V0.9 - Fixed bug:- OSCCAL not initialized in 12F675 code!
;                 - Detect throttle channel. The throttle is held OFF after
;                   failsafe, until re-armed manually. This prevents cyling
;                   into and out of failsafe due to electrical noise coming
;                   from the motor.
;
; 2004/6/20  V1.0 - Using TMR0 to detect loss of signal. This prevents lockup
;                   during a clean signal loss (no noise) which may occur if
;                   used in a receiver which has muting.
;                 - TMR0 is also used to set frame repeat time in failsafe.
;    - Fixed bug:- Initial channel output values were wrong.
;
; 2004/10/24 V1.1 - Positive and Negative shift versions.
;    - Ignore short glitches on signal transitions.
;    - Ensure throttle is low in failsafe, even if it was maxiumum
;                   at startup (possible requirement for ESC programming).
;
; 2004/12/12 V1.2 - Fixed bug: JR throttle arming was disabled due to a typo!
;
; 2005/1/20  V1.3 - Now accepts pulse widths from 180uS to 700uS.
;
; 2005/11/16 V1.4 - Change channels to 5 - 8.  by Y.C.Tseng
;                   disable the ARM_THROTTLE and DETECT_JR
;
; -----------------------------------------------------------------------------
;#DEFINE ARM_THROTTLE ; enable if throttle arming control wanted.   
;#DEFINE DETECT_JR ; enable for JR/Airtronics/GWS throttle detection.
#DEFINE version  "1.4"
#DEFINE Negative_Shift  ; enable for Futaba/Hitec on 72MHz

; Make sure that PROCESSOR and <include> file are compatible with your CPU!
; 12C508(A) and 12C509(A) can use 12C508 definitions. 12F629 can use 12F675
; definitions (just don't try to use the A/D module...)
;#DEFINE __12C508 ; enable if processor not specified elsewhere
;#DEFINE __12F675 ; (MPLAB:- use menu <Configure/Select_Device>)
;#DEFINE NO_OSCCAL  ; enable if OSCCAL value was erased!

ifdef   __12C508
PROCESSOR PIC12C508
        INCLUDE   <P12C508.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
else
        PROCESSOR PIC12F675
        INCLUDE   <P12F675.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
endif
        radix     dec
errorlevel 0,-305,-302

; Bit definitions for the GPIO register and the TRIS register
#DEFINE CH_1     0    ; pin 7   Channel 5 output
#DEFINE CH_2  1    ; pin 6   Channel 6 output
#DEFINE CH_3  2    ; pin 5   Channel 7 output
#DEFINE PPM_in  3    ; pin 4   input pulse stream
#DEFINE CH_4  4    ; pin 3   Channel 8 Output
#DEFINE LED    5    ; pin 2   Signal Indicator LED
#DEFINE TrisBits H'FF'&~((1<<CH_1)|(1<<CH_2)|(1<<CH_3)|(1<<CH_4)|(1<<LED))

; Bits to be set with the OPTION instruction
;   No wake up
;   No weak pullups
;   Timer 0 source internal
;   Prescaler to Timer 0, divide by 256.
;
#DEFINE OptionBits B'11000111'
; =========================================================================
; Macro for generating short time delays
;
NO_OP           MACRO   count
NO_OP_COUNT     SET     count
                WHILE   NO_OP_COUNT>1
  goto $+1  ; 2 clocks
NO_OP_COUNT     SET     NO_OP_COUNT-2
                ENDW
  IF NO_OP_COUNT
  nop   ; 1 clock
  ENDIF
                ENDM
;===========================================================================
; Macro to create offsets for variables in RAM
;
  ifdef __12C508
ByteAddr SET 7
  else
ByteAddr SET 32  ; user RAM starts here
  endif
BYTE            MACRO     ByteName
ByteName        EQU       ByteAddr
ByteAddr SET       ByteAddr+1
                ENDM

[ 本帖最后由 想飞的咸鱼 于 2007-7-14 22:56 编辑 ]

欢迎继续阅读楼主其他信息

27
 楼主| 发表于 2007-7-16 14:50 | 只看该作者
:em00: 谢谢狐狸兄啊    我再试试你给的代码若不行就买个专用编程器 喜欢上这玩意也中毒啊:em17:
26
发表于 2007-7-16 13:37 | 只看该作者
下面的是楼主贴出来的程序编译出来的HEX文件:
:020000040000FA
:02000000280ACC
:10001000520858084408450843083508300838088D
:100020002D082D08560831082E0833082D082D08F4
:10003000410852084D085408480852084F0854080F
:100040004408450854084508430854084A0852081B
:1000500007048307070525000400C70C020066009B
:10006000C80C0600840A7A0C2800050C3C00380AEB
:10007000E800FC02370A6607410A0000E8023B0A72
:1000800001085C0C880003060108060C88000307C1
:100090000108050C3C004C0AE800FC024B0A66060D
:1000A00001080000E8024F0AA802660600080000E6
:1000B000E803550A02080D0206056C0906040E0243
:1000C00026056C0926040F0246056C094604100239
:1000D00086056C09860400083D007C0C3C0000008D
:1000E00004000000FC026F0A000004000000FD0292
:1000F000740A00083C00C70C3D0004000000FD022B
:100100007D0AFC027B0A00080706990A6700FA0CC0
:100110007A09FA0C7A09A6057D0C31003200330009
:1001200034002C000A0C3900190C3A000A0C3B0070
:10013000A90A010C3A002707A90A15022D00160288
:100140002E0017022F00180230005B09A7040A0CCA
:100150003B00A60504007C00090C3D006607B80AB8
:10016000000004000000FC004306FD02AE0AED0A98
:100170006800FC004306FD004306ED0A6606AE0A71
:10018000E803B90A270C21000400E106ED0A66071E
:10019000C40A4704CB0A00003309FF0E4307ED0AE7
:1001A000080229003309FF0E4307ED0A08022A005E
:1001B0003309FF0E4307ED0A08022B003309FF0E37
:1001C0004307E60A08022C004705FA0A020F430714
:1001D000ED0A2707FA0A6707FA0A04004A0C8100A9
:1001E0000307ED0A0A0C3B00FA02F70A990A2706F0
:1001F0005B09A90A0902F10111032D000A02F201AB
:1002000012032E000B02F30113032F000C02F40162
:10021000140330002707230BA706220B5B0C87066D
:100220008D0087078F000307180B0A0C3B001C0B7F
:10023000FB021C0BA705220B170287072F001502D4
:1002400087062D005B09090231000A0232000B0209
:1002500033000C023400190C3A00A6042706510B97
:100260000400F902510B470667050D0235000E0226
:1002700036000F0237001002380027055B0C95008E
:100280000307480B9E0C950003074A0B3A0C3500F8
:100290008705500B9E0C97000307500B3A0C370054
:0402A000A705AA0AFA
:021FFE00EE0FE4
:00000001FF

注意烧写时熔丝的选择:
MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
这个东西俺作红外线遥控时试过,挺不错的;
25
 楼主| 发表于 2007-7-16 12:35 | 只看该作者
这个烧写软件是TOP2005编程器带的  你用的PIC专用编程器是在PIC16买的吗 是哪个型号能告诉我吗 避免再次买错:loveliness:
24
发表于 2007-7-16 11:16 | 只看该作者

感谢楼主

这样代码也可以直接贴出来,非常感谢!
23
发表于 2007-7-16 10:44 | 只看该作者
:em26:
22
发表于 2007-7-16 10:09 | 只看该作者
没错,你这个烧写软件是哪个软件?最好是用PIC专用的编成器,其他的好像要出问题;
21
发表于 2007-7-15 22:27 | 只看该作者
晕,这样求助啊
20
 楼主| 发表于 2007-7-15 20:46 | 只看该作者
狐狸帮忙看看着配置对不对   还有给我一个邮箱地址吧我把HEX文件发给你试一试看看行不行


19
 楼主| 发表于 2007-7-15 18:29 | 只看该作者
[quote]原帖由 狐狸 于 2007-7-15 13:26 发表
注意下面这一段:
PROCESSOR PIC12C508
        INCLUDE   <P12C508.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
else
        PROCESSOR PIC12F675
        INCLUDE   <P12F675.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
烧写程序时熔丝配置要与此相同,不然会没法使用的;


果然有玄机啊  我再试试  谢谢狐狸啊
18
发表于 2007-7-15 17:04 | 只看该作者
改成AVR的就好了,看不懂PIC的,请能改成AVR的汇编,或者把完整的贴上来,看能不能改成用M8或者M16解码多通道.
17
发表于 2007-7-15 16:35 | 只看该作者
打蚊子何必用高射炮,楼上?嗬嗬:em16: :em15:
16
发表于 2007-7-15 15:40 | 只看该作者
用M8比PIC508好些吧:loveliness:
15
发表于 2007-7-15 15:01 | 只看该作者
好...好长.....:em17:
14
发表于 2007-7-15 14:34 | 只看该作者
高手,看不懂,但还是要假装懂,嘿嘿:em15:
13
发表于 2007-7-15 14:13 | 只看该作者
果然楼主拷贝错误,呵呵,找到原来拷的,一次编译通过;
12
发表于 2007-7-15 13:55 | 只看该作者
这个是汇编的,刚才试着编译了一下,通不过,一大堆错误提示,是不是楼主拷贝出错了?:em22: :em22:
11
发表于 2007-7-15 13:45 | 只看该作者
:em22: :em22:  太深了???????????

这是C语言?   还是汇遍啊??????
10
发表于 2007-7-15 13:26 | 只看该作者
这个解码程序已经有不少人做成功过,在RCGROUP上有不少讨论,算是比较经典的解码程序;
相近的还有六通道的;
TOP2005这一类的通用编程器有时候烧写PIC会出问题,俺用过TOP的,还有MAX的都会有很多的废片,还是老老实实的买了个240元的PIC专用编程器,呵呵,这一两年只有几片废的,还是自己搞错插槽废的;建议楼主到PIC16上看看;
如果是试招,还是先不要用PIC12C508,直接用12F675或12F509替代,即使不对,也可以重新烧写程序;
注意下面这一段:
PROCESSOR PIC12C508
        INCLUDE   <P12C508.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
else
        PROCESSOR PIC12F675
        INCLUDE   <P12F675.inc>
__CONFIG  _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
烧写程序时熔丝配置要与此相同,不然会没法使用的;
9
发表于 2007-7-15 03:41 | 只看该作者
这是啥呢
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

关闭

【站内推荐】上一条 /1 下一条

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