Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Constant Carrier Wave #609

Merged
merged 10 commits into from
Jul 20, 2020
Merged

Added Constant Carrier Wave #609

merged 10 commits into from
Jul 20, 2020

Conversation

waltbar
Copy link
Contributor

@waltbar waltbar commented Jul 19, 2020

I have added code to include the constant carrier wave functionality as documented in the data sheet appendix C

@Avamander
Copy link
Member

Please rebase on top of current master.

@waltbar
Copy link
Contributor Author

waltbar commented Jul 19, 2020

OK. Done.

@Avamander
Copy link
Member

Thanks. Though the PR still contains too many unrelated changes at the moment, can you please revert unrelated changes?

@waltbar
Copy link
Contributor Author

waltbar commented Jul 19, 2020

Not sure how to do that. Here is what i have changed.
RF24.cpp

/***************************************************************************/
void RF24::startConstCarrier(uint8_t level, uint8_t channel)
{
    write_register(RF_SETUP, (read_register(RF_SETUP)) | _BV(CONT_WAVE));
    write_register(RF_SETUP, (read_register(RF_SETUP)) | _BV(PLL_LOCK));
    setPALevel(level);
    setChannel(channel);
    IF_SERIAL_DEBUG(printf("RF_SETUO=%i\r\n", read_register(RF_SETUP)));
    ce(HIGH);
}

/****************************************************************************/
void RF24::stopConstCarrier()
{
    ce(LOW);
}

RF24.h

class RF24
{
pubilc:
.
.
.
/**
     * Transmission of constant carrier wave with defined frequency and output power
     * 
     *     
     */
    void startConstCarrier(uint8_t level, uint8_t channel);

    /**
     * Stop transmission of constant wave
     *
     *     
     */
    void stopConstCarrier(void);

nRF24L01.h

/* Bit Mnemonics */
.
.
.
#define CONT_WAVE 7

@TMRh20
Copy link
Member

TMRh20 commented Jul 20, 2020

@waltbar Basically you need to make your changes without modifying the rest of the file. Typically just don't to auto-formatting etc., just edit the file, make the changes then commit to github.

Have not tested, but so far would suggest hte following changes:

RF24.h
void startConstCarrier(rf24_pa_dbm_e level, uint8_t channel );

RF24.cpp
void RF24::startConstCarrier(rf24_pa_dbm_e level, uint8_t channel )
{
    write_register(RF_SETUP, (read_register(RF_SETUP)) | _BV(CONT_WAVE));
    write_register(RF_SETUP, (read_register(RF_SETUP)) | _BV(PLL_LOCK));
    setPALevel(level);
    setChannel(channel);
    IF_SERIAL_DEBUG( printf_P(PSTR("RF_SETUP=%02x\r\n"), read_register(RF_SETUP)  ) );
    ce(HIGH);
}
void RF24::stopConstCarrier()
{   
    write_register(RF_SETUP, (read_register(RF_SETUP)) & ~_BV(CONT_WAVE));
    write_register(RF_SETUP, (read_register(RF_SETUP)) & ~_BV(PLL_LOCK));
    ce(LOW);
}

The code is quickly thrown together so might be syntax errors but the gist is:

  1. Change function startConstCarrier to use RF24 enum for PA_Level
  2. Change same to printf in hex and use progmem for the string
  3. Disable the constCarrier() configuration instead of just stopping it in stopConstCarrier() function

With these modifications I think this change would be acceptable, would just need to test a bit.

@waltbar
Copy link
Contributor Author

waltbar commented Jul 20, 2020

Code prettyfier is the culprit.
I added your suggestions to the functions. I haven't got proper equipment to test functionality. I have checked with a poor man's frequency analyzer using the nrf24l01 module.
Happy to contribute and sorry for the formatting mess.

Avamander
Avamander previously approved these changes Jul 20, 2020
Copy link
Member

@Avamander Avamander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay to me now, what do you think @TMRh20?

@TMRh20
Copy link
Member

TMRh20 commented Jul 20, 2020

Looking good, the only other change I would suggest would be to move the declaration in the RF24.h file out of the "Deprecated" section and just below the "failureDetected" declaration.

Other than that, here are my test results (a pretty distinct result):
Scanner Code:

/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

/**
 * Channel scanner
 *
 * Example to detect interference on the various channels available.
 * This is a good diagnostic tool to check whether you're picking a
 * good channel for your application.
 *
 * Inspired by cpixip.
 * See http://arduino.cc/forum/index.php/topic,54795.0.html
 */

#include "RF24.h"
//#include "printf.h"

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 7 & 8

RF24 radio(7,8);

//
// Channel info
//

const uint8_t num_channels = 50;
uint8_t values[num_channels];

//
// Setup
//

void setup(void)
{
  //
  // Print preamble
  //

  Serial.begin(115200);
  //printf_begin();
  Serial.println(F("\n\rRF24/examples/scanner/"));

  //
  // Setup and configure rf radio
  //

  radio.begin();
  radio.setAutoAck(false);

  // Get into standby mode
  radio.startListening();
  radio.stopListening();
  radio.printDetails();

  //delay(1000);
  // Print out header, high then low digit
  int i = 0;
  while ( i < num_channels )
  {
    //printf("%02x",i>>4);
    Serial.print(i>>4,HEX);
    ++i;
  }
  Serial.println();
  i = 0;
  while ( i < num_channels )
  {
    //printf("%02x",i&0xf);
    Serial.print(i&0xf,HEX);
    ++i;
  }
  Serial.println();
  //delay(1000);
}

//
// Loop
//

const int num_reps = 100;

void loop(void)
{
  // Clear measurement values
  memset(values,0,sizeof(values));

  // Scan all channels num_reps times
  int rep_counter = num_reps;
  while (rep_counter--)
  {
    int i = num_channels;
    while (i--)
    {
      // Select this channel
      radio.setChannel(i);

      // Listen for a little
      radio.startListening();
      delayMicroseconds(128);
      radio.stopListening();

      // Did we get a carrier?
      if ( radio.testCarrier() ){
        ++values[i];
      }
    }
  }

  // Print out channel measurements, clamped to a single hex digit
  int i = 0;
  while ( i < num_channels )
  {
    //printf("%02x",min(0xf,values[i]));
    Serial.print(min(0xf,values[i]),HEX);
    ++i;
  }
  Serial.println();
}

// vim:ai:cin:sts=2 sw=2 ft=cpp

CCW Output Code:

#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(7,8);


void setup() {

  Serial.begin(115200);
  printf_begin();
  Serial.println(F("\n\rRF24/CCW"));
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  radio.printDetails();
  
}



void loop() {

  if(Serial.available()){
    char c = Serial.read();
    if(c == 'g'){
      radio.stopListening();
      delay(2);
      Serial.println("Starting Carrier Out");
      radio.startConstCarrier(RF24_PA_LOW,40);  
    }else
    if(c == 'e'){
      radio.stopConstCarrier();
      Serial.println("Stopping Carrier Out");
    }
  }
}

Scanner output:

00000000000000001111111111111111222222222222222233
0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01
00000000000000424242322000000000000000000000000000
10000000000000211111111000000000000000000000000000
00000000000000112113242100000000000000000000000000
00000000000000242434211001000000000000000000000000
21100000000000121111222000000000000000000000000000
12100000000100222352424000000000000000000000000000
21200000000000212121111000000000000000000000000000
011000000000004332222420000000000000000FFF00000000
124000000000002212122320000000000000000FFF00000000
111000100000001212102231100000000000000FFF00000000
110000000001002243433230000000000000000FFF00000000
21100000000000212111111000000000000000022200000000
01100000000000222223242000000000000000000000000000
00000000000000121312121000000000000000000000000000
00000010000000121322222000000000000000000000000000
00000000000000232211212000000000000000000000000000

Overview:
I started up the scanner, then got some regular traffic going on channel 1, which the scanner picks up. Then I start the CCW output on channel 40, which very clearly shows up in the scanner output. Then I stop the traffic and CCW output.

@TMRh20
Copy link
Member

TMRh20 commented Jul 20, 2020

This is pretty cool, it gives great results with the scanner example and makes an easy way to verify signal, so I've already got the example updated to include this functionality. You can switch back and forth between scanning and output of CCW. Going to commit as soon as this code is in. 👍

Copy link
Member

@TMRh20 TMRh20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

@TMRh20 TMRh20 merged commit 0eada50 into nRF24:master Jul 20, 2020
TMRh20 added a commit that referenced this pull request Jul 20, 2020
- Add feature to output a CCW on a specified channel and power level to the scanner example per #609
- Changed scanner example to use Serial prints instead of printf
- Removed unneeded delays
@waltbar
Copy link
Contributor Author

waltbar commented Jul 21, 2020

Cool

@2bndy5 2bndy5 mentioned this pull request Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants