I use a sender and receiver HE433-2/R of Heiland (http://www.heiland-electronic.de/uhf-mod.htm) for my turnouts/points of my gradenrailway. I want to use the digital output of the receiver to control directly the servo’s used to switch the pneumatic switches. http://lichtenbelt.com/jan/trein/kleintjestoom.htm (see number 3)
I first wrote an assembler program for PICKit 2 and later an improved assembler version for Flowcode 4. Time critical steps are found by just counting the program steps (no timer used). It works correctly, but it does not use the simple Flowcode possibilities. So I thought that must be possible to program in Flowcode 4. But after 3 weeks without success. If you like to help please read the details below.
The sequence of the digital output has not been published, but with a scope, see picture, I found out that there are 4 bytes, repeated in a time frame of 84 bits. The 4 bytes are preceeded by a startbit β€1β€ and followed by a controlbit (β€1β€ for an even number of bits in the byte, else β€0β€). The total length is thus 10 bits followed by 6 bits β€0β€. Between the last control bit and the first start bit of the next sequence are 26 bits β€0β€.
There is one problem, the bit width is about 120 usec and the distance between two bits is about 104 usec. That means two bits β€1β€ will overlap and detection of these two bits simple by detection low-high and high-low is not possible. One must know the bit-width and the bit-distance first.
An example is given in the picture. High is β€0β€and low is β€1β€. The first byte is always 0x00, the second address-byte is in this case also 0x00, the third data-byte is in this case 0x80 (see overlap with the startbit) and the forth byte is a controlbyte (which I skip, because I do not know the mathematics for it). The peak at about 9 msec is the first startbit of the second sequence.
I used the following steps
1) Find the bit-distance: Check for at least 20 bits (about 2 msec) the input (E2 in my case for PIC16F877A) to be high. The next bit must be the first start bit. Start the timer (TRM0 with 19200Hz, 52 usec) and wait about 8 msec and find the first bit of the 2 sequence. The time/84 is the distance between the bits.
2) To make it easy, take the bit-width = bit-distance + 15 usec. (bit-width is less critical)
3) Repeat 1) to get the first start bit β€1β€, wait at least a bit-width and read the 8 bits of the first byte. This must be 0x00 and the control bit must be β€1β€
4) After this control bit, wait about 5 bits and check for the next start bit. Read the second startbit-byte-controlbit. Repeat 4) for the third byte and forget the forth controlbyte.
Reading HE433-2/R data with Flowcode 4
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Reading HE433-2/R data with Flowcode 4
- Attachments
-
- 4 bytes 0x00, 0x00, 0x80 and 0x40 in a sequence of about 9 msec. "0"= 5V and "1"= 0V. See text for details
- P1030350_bw.jpg (226.42 KiB) Viewed 3179 times
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Reading HE433-2/R data with Flowcode 4
The problem have been solved. With very well and acurate help of Ben.
Jan Lichtenbelt
Jan Lichtenbelt
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Reading HE433-2/R data with Flowcode 4
How I solved the problem. Using Flowcode can introduce delay time just by program steps used. The delay time is not known and will vary when changing the program.
The sampling of the 8 bits is simple realised by using interrupt time of 104 usec (19200 Hz). The start of the sampling is a problem. The first start bit (first peak in the figure) can easily be found. I varied a delay time before starting the bit-sampling procedure in a way that the first byte (which is always 0x00) will give after sampling the right value. If the delay time is to short or to long the byte found will be 0x80 (start bit detected) or 0x01(control bit detected). The realised delay time is a the mean value of the shortest and longest delay time which give as result 0x00. The value found is 145 usec.
Remark: This deviates about 20 usec from the theoretical value, due to (variable amount of) program steps and due to a possible deviation in sampling time from the microchip compared to the HE433-2/R used.
The sampling of the 8 bits is simple realised by using interrupt time of 104 usec (19200 Hz). The start of the sampling is a problem. The first start bit (first peak in the figure) can easily be found. I varied a delay time before starting the bit-sampling procedure in a way that the first byte (which is always 0x00) will give after sampling the right value. If the delay time is to short or to long the byte found will be 0x80 (start bit detected) or 0x01(control bit detected). The realised delay time is a the mean value of the shortest and longest delay time which give as result 0x00. The value found is 145 usec.
Remark: This deviates about 20 usec from the theoretical value, due to (variable amount of) program steps and due to a possible deviation in sampling time from the microchip compared to the HE433-2/R used.