Phil's lockdown project - a 4ch propo NRF24 set

Any old or new electronic projects on the go
Locked
WernerL
Posts: 27
Joined: 22 Jan 2020, 02:30

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by WernerL »

Wow! Those TIL311 bring up fond memories! They are vintage in itself!
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by Phil_G »

Hi Werner, could I just confirm something with you, in my receiver code I found that after switching channels, I had to re-open the pipe and also switch acks off again, without these commands there would be no reception on the new channel, which of course would trigger another channel change and a never-ending loop.
With the extra commands its fine, I tried this and variations of it many times to confirm it was necessary, did you find the same?

Code: Select all

  now = millis();
  if ( now - lastRecvTime > lostpkTime ) {  // if no packet on this channel, try next
    if (++chcounter > 5) chcounter = 0;
    PORTC = chcounter;  // optionally show current channel slot on TIL311
    radio.setChannel(mychannels[chcounter]);  delayMicroseconds(500);
    radio.openReadingPipe(1, pipeIn);         delayMicroseconds(500);
    radio.setAutoAck(false);                  delayMicroseconds(500);
  }
Cheers
Phil
WernerL
Posts: 27
Joined: 22 Jan 2020, 02:30

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by WernerL »

Hi Phil,

It is not necessary to re-open the pipe or performing any other kind of initialization to switch channels.

My channel-hopping code looks like this:

Code: Select all

rf_clear_ce();
hop_index = (hop_index + 1) % NUMBER_OF_HOP_CHANNELS;
rf_set_channel(hop_data[hop_index]);
rf_set_ce();
The rf_clear_ce() and rf_set_ce() functions simply switch the CE pin low/high. The set_ce high() function also has a 4 us delay at the end because the datasheet says it is necessary to wait 4us before asserting the CS the next time, so the delay is there just to ensure this can never be violated.

The rf_set_channel() function simply writes the channel number (0..125) to the corresponding nRF24 register.

You can find the source code here: https://github.com/laneboysrc/nrf24l01- ... r/firmware
The file rc_receiver.c has the main code logic. The process_receiving() function around line 641 contains the hop logic, which is triggered by a flag that is set from a periodic timer interrupt (and synchronized whenever a package is received).

The low-level rf_ functions in rf.c are the equivalent of the nRF24 Arduino library, there should be a lot of communality.

The RF initialization can be found in rc_receiver.c, function restart_packet_receiving() around line 200. It sets up all the nRF24 parameters like CRC, pipe, data rate, address, etc.

hope this helps, Werner
User avatar
F2B
Posts: 200
Joined: 16 Feb 2018, 11:23
Location: 20 m NE of Amsterdam

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by F2B »

WernerL wrote: 09 Apr 2020, 04:26 Wow! Those TIL311 bring up fond memories! They are vintage in itself!
TIL indeed. Vintage?
But so are we.... :lol:
F2B or not to be....
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by Phil_G »

I found my problem, it was a silly logic flow problem, masked by the delay of those redundant commands - its fixed properly now. My fault, sorry chaps.

In a nutshell, theres a timer that notes when the last packet was received. If that timer gets to 1 second, it goes to failsafe. If it gets to 50ms with no packet on the current channel, it swaps channels, but crucially the last-packet-received time is still stale (over 50ms) so without waiting for any traffic it moved onto the next channel, the timer is still stale... and so on. I must be getting dozy in my old age.

Anyway its all fixed and working perfectly again, without delays or unnecessary 'extra commands' (which only worked because of the delay they introduced!). The channel change is completely unnoticable in use, other than the numbers on the TIL311.

The first post is updated with the new sketches, if anyone fancies a play with this but finds the number of updates sounds disheartening, every version posted does work fine, this latest one answers the question "why did I need a delay after changing channels?".

Other than the RF side, everything else is as you'd expect, with the usual minute-minder, Vtail and elevon mixes, single-channel escapement emulation with 2 rattler speeds, hard & soft throttle locks, inactivity alarm, rates, expo, reversing etc. I reckon you could make a tx & rx for under a fiver each :D

Thanks again for your support Werner, I need to spend quite some time studying your code as its so complex (for me!).
There are some very clever programmers on here, unfortunately you've found the village idiot :D :D :D

Cheers
Phil
Tobe
Posts: 665
Joined: 16 Feb 2018, 06:19
Location: Varberg or Stockholm, Sweden

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by Tobe »

Lovely project Phil once again you have gifted us with an amazing and superb project. I have completed a test set up and it sure works nicely and I see it ideal to use in small models.
Cheers,

Tobe
WernerL
Posts: 27
Joined: 22 Jan 2020, 02:30

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by WernerL »

Fantastic Phil, great you hear you've got it sorted out!
And don't be so humble, you are doing magnificent work. It is spectacular what you and many others here have achieved. So many ideas, learning and especially sharing!

Regarding the "RF acknowledgements": they would be useful for "telemetry" as well. I deliberately decided against this route as I did not want to make the project even more complicated. It would also require adding a high-power nRF module on the receiver, which I wasn't prepared to do.


The frequency hopping stuff is quite simple really.
Both transmitter and receiver use a pre-arranged list of 20 hop frequencies (exchanged through a one-time binding procedure, which I don't talk about for now to keep things simple).

On the transmitter side, a packet is sent every 5 ms. For each packet, the transmitter changes to the next hop frequency in the list, round-robin style. The 5ms timing is kept as precise as possible.

On the receiver side, the receiver stays on the first hop frequency until it catches a packet from the transmitter. (20 hops, one hop every 5 ms means after worst case within 100 ms the receiver should get a packet). Once the packet has been received, it starts a timer that is a bit larger than the 5 ms, and changes the receive channel to listen on next hop frequency. It listens now for the next packet on this new hop frequency. If the packet arrives, the 5+ ms timer is restarted and the next hop frequency is chosen, and so on.

If the packet got lost, the slightly-greater-than-5 ms timer expires. We then switch to the next hop channel and restart the time out, but this time with exactly 5 ms (because we don't want to drift away from the transmitter, we just want the timeout to be slightly behind the transmitter).

This continues until we either receive a packet, or if we miss multiple packets in a row (I think 6 in my case). If we miss 6 packets in a row, then the receiver assumes it is completely out of sync with the transmitter, and switches to the first hop frequency, where it listens until it receives a valid packet from the transmitter (should be less than 100 ms). Then the hopping restarts as described above.

Failsafe kicks in if there are no received packets within 600 ms.

This protocol is not my invention (of course), I reverse engineered a commercial nRF24 based RC system and went from there. I was actually surprised how simple it all is... But then: simple is good!

happy pulsing, Werner
User avatar
Shaun
Posts: 1049
Joined: 15 Feb 2018, 21:49
Location: West Yorkshire

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by Shaun »

Here's my lockdown project. Completely Arduino
free.

Built yesterday after I decided to redesign an old s/c model by simplifying it, electrifying it and especially for Phil adding elevons 😉 ..The original had 1/8th inch ply fus doublers and a 1/8" ply fus floor at the front. It was more like a flying rounders bat. At under 2lbs and 400 watts it should be interesting.

Plan will be in mag soon.

Anybody know what it is?

Shaun
IMG_20200410_145359512_HDR.jpg
GarydNB
Posts: 282
Joined: 15 Feb 2018, 23:12

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by GarydNB »

A waste of good balsa?
User avatar
Shaun
Posts: 1049
Joined: 15 Feb 2018, 21:49
Location: West Yorkshire

Re: Phil's lockdown project - a 4ch propo NRF24 set

Post by Shaun »

It's for people who don't like building wings. At 26" diameter it would make a hell of a table tennis bat.
Locked