IR remote test, based on Arduino IRRemote lib.

Dependencies:   mbed

IR remote test, based on Arduino IRremote lib.

https://www.pjrc.com/teensy/td_libs_IRremote.html

Uses PWM for carrier and timer for 50us sensor reads. for k64f, one could use CMT.

Committer:
manitou
Date:
Wed Apr 13 11:18:39 2016 +0000
Revision:
1:af81e02b8c7b
Parent:
0:785739d5a30a
edit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manitou 0:785739d5a30a 1 #define RECV_TIMER 2
manitou 0:785739d5a30a 2 // maple pwm pin/timer/channel predefined and vary by processor
manitou 0:785739d5a30a 3 // maple RET6
manitou 0:785739d5a30a 4 #define PWM_PIN 24
manitou 0:785739d5a30a 5 #define PWM_TIMER 4
manitou 0:785739d5a30a 6 #define PWM_TIMER_CH TIMER_CH4
manitou 0:785739d5a30a 7 #define PWM_DUTY 2 //2 50% 4 25% hi
manitou 0:785739d5a30a 8
manitou 0:785739d5a30a 9 #define RAWBUF 76 // Length of raw duration buffer
manitou 0:785739d5a30a 10
manitou 0:785739d5a30a 11 #define USECPERTICK 50 // microseconds per clock interrupt tick
manitou 0:785739d5a30a 12
manitou 0:785739d5a30a 13 // Marks tend to be 100us too long, and spaces 100us too short
manitou 0:785739d5a30a 14 // when received due to sensor lag.
manitou 0:785739d5a30a 15 #define MARK_EXCESS 100
manitou 0:785739d5a30a 16
manitou 0:785739d5a30a 17 // Values for decode_type
manitou 0:785739d5a30a 18 #define NEC 1
manitou 0:785739d5a30a 19 #define SONY 2
manitou 0:785739d5a30a 20 #define RC5 3
manitou 0:785739d5a30a 21 #define RC6 4
manitou 0:785739d5a30a 22 #define UNKNOWN -1
manitou 0:785739d5a30a 23
manitou 0:785739d5a30a 24 #define TOLERANCE 25 // percent tolerance in measurements
manitou 0:785739d5a30a 25 #define LTOL (1.0 - TOLERANCE/100.)
manitou 0:785739d5a30a 26 #define UTOL (1.0 + TOLERANCE/100.)
manitou 0:785739d5a30a 27
manitou 0:785739d5a30a 28 #define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
manitou 0:785739d5a30a 29 #define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
manitou 0:785739d5a30a 30
manitou 0:785739d5a30a 31 #define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us))
manitou 0:785739d5a30a 32 #define MATCH_MARK(measured_ticks, desired_us) MATCH(measured_ticks, (desired_us) + MARK_EXCESS)
manitou 0:785739d5a30a 33 #define MATCH_SPACE(measured_ticks, desired_us) MATCH((measured_ticks), (desired_us) - MARK_EXCESS)
manitou 0:785739d5a30a 34
manitou 0:785739d5a30a 35
manitou 0:785739d5a30a 36 #define _GAP 5000 // Minimum gap between transmissions us
manitou 0:785739d5a30a 37 #define GAP_TICKS (_GAP/USECPERTICK)
manitou 0:785739d5a30a 38
manitou 0:785739d5a30a 39 // receiver states
manitou 0:785739d5a30a 40 #define STATE_IDLE 2
manitou 0:785739d5a30a 41 #define STATE_MARK 3
manitou 0:785739d5a30a 42 #define STATE_SPACE 4
manitou 0:785739d5a30a 43 #define STATE_STOP 5
manitou 0:785739d5a30a 44
manitou 0:785739d5a30a 45 // IR detector output is active low
manitou 0:785739d5a30a 46 #define MARK 0
manitou 0:785739d5a30a 47 #define SPACE 1
manitou 0:785739d5a30a 48
manitou 0:785739d5a30a 49 #define TOPBIT 0x80000000
manitou 0:785739d5a30a 50
manitou 0:785739d5a30a 51 #define ERR 0
manitou 0:785739d5a30a 52 #define DECODED 1
manitou 0:785739d5a30a 53
manitou 0:785739d5a30a 54 // duration in us
manitou 0:785739d5a30a 55 #define SONY_HDR_MARK 2400
manitou 0:785739d5a30a 56 #define SONY_HDR_SPACE 600
manitou 0:785739d5a30a 57 #define SONY_ONE_MARK 1200
manitou 0:785739d5a30a 58 #define SONY_ZERO_MARK 600
manitou 0:785739d5a30a 59 #define SONY_RPT_LENGTH 45000
manitou 0:785739d5a30a 60 #define SONY_BITS 12