Go Down

Topic: AD9850 DDS with Hitachi compatable LCD (16x2) and a rotary encoder (Read 12233 times) previous topic - next topic

nivar

Hi,
         I am trying to assemble a HF synthesized signal generator with the LCD readout and a rotary encoder with push button switch. I tried to instal the following code in the IDE (ver.1.05) but getting the following 3 error messages. The author of this code says there is no problem with it and many people had in the past successfully used the same. The rotary encoder in stand alone mode with the standard codes (copied from Arduino playground and other places ) works well. So I think the encoder code is already installed in the IDE library. Hence I request experts in this forum to kindly help me in resolving the issue . Thanks in advance for your time. Further I am not a big expert in coding of any sort as I am essentially a hardware guy.

"Step 11.error 'Encoder' does not name a type

Step 40 in function 'void_vector_5()';
      error 'r' was not declared in this scope    

Step 42 error 'DIR_CW' was not declared in this scope
code"


The full program is reproduced below.

Code: [Select]
#include <LiquidCrystal.h>
#include <rotary.h>

//Setup some items
#define W_CLK 8   // Pin 8 - connect to AD9850 module word load clock pin (CLK)
#define FQ_UD 9   // Pin 9 - connect to freq update pin (FQ)
#define DATA 10   // Pin 10 - connect to serial data load pin (DATA)
#define RESET 11  // Pin 11 - connect to reset pin (RST)
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
Rotary r = Rotary(2,3); // sets the pins the rotary encoder uses.  Must be interrupt pins.
LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // I used an odd pin combination because I need pin 2 and 3 for the interrupts.
int_fast32_t rx=7200000; // Starting frequency of VFO
int_fast32_t rx2=1; // variable to hold the updated frequency
int_fast32_t increment = 10; // starting VFO update increment in HZ.
int buttonstate = 0;
String hertz = "10 Hz";
int  hertzPosition = 5;
byte ones,tens,hundreds,thousands,tenthousands,hundredthousands,millions ;  //Placeholders

void setup() {
 pinMode(A0,INPUT); // Connect to a button that goes to GND on push
 digitalWrite(A0,HIGH);
 lcd.begin(16, 2);
 PCICR |= (1 << PCIE2);
 PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
 sei();
 pinMode(FQ_UD, OUTPUT);
 pinMode(W_CLK, OUTPUT);
 pinMode(DATA, OUTPUT);
 pinMode(RESET, OUTPUT);
 pulseHigh(RESET);
 pulseHigh(W_CLK);
 pulseHigh(FQ_UD);  // this pulse enables serial mode on the AD9850 - Datasheet page 12.
 lcd.setCursor(hertzPosition,1);    
 lcd.print(hertz);
}

ISR(PCINT2_vect) {
 unsigned char result = r.process();
 if (result) {    
   if (result == DIR_CW){rx=rx+increment;}
   else {rx=rx-increment;};      
     if (rx >=30000000){rx=rx2;}; // UPPER VFO LIMIT
     if (rx <=1000000){rx=rx2;}; // LOWER VFO LIMIT
 }
}



// frequency calc from datasheet page 8 = <sys clock> * <frequency tuning word>/2^32
void sendFrequency(double frequency) {  
 int32_t freq = frequency * 4294967295/125000000;  // note 125 MHz clock on 9850.  You can make 'slight' tuning variations here by adjusting the clock frequency.
 for (int b=0; b<4; b++, freq>>=8) {
   tfr_byte(freq & 0xFF);
 }
 tfr_byte(0x000);   // Final control byte, all 0 for 9850 chip
 pulseHigh(FQ_UD);  // Done!  Should see output
}
// transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
void tfr_byte(byte data)
{
 for (int i=0; i<8; i++, data>>=1) {
   digitalWrite(DATA, data & 0x01);
   pulseHigh(W_CLK);   //after each bit sent, CLK is pulsed high
 }
}



void setincrement(){
 if(increment == 10){increment = 50; hertz = "50 Hz"; hertzPosition=5;}
 else if (increment == 50){increment = 100;  hertz = "100 Hz"; hertzPosition=4;}
 else if (increment == 100){increment = 500; hertz="500 Hz"; hertzPosition=4;}
 else if (increment == 500){increment = 1000; hertz="1 Khz"; hertzPosition=6;}
 else if (increment == 1000){increment = 2500; hertz="2.5 Khz"; hertzPosition=4;}
 else if (increment == 2500){increment = 5000; hertz="5 Khz"; hertzPosition=6;}
 else if (increment == 5000){increment = 10000; hertz="10 Khz"; hertzPosition=5;}
 else if (increment == 10000){increment = 100000; hertz="100 Khz"; hertzPosition=4;}
 else if (increment == 100000){increment = 1000000; hertz="1 Mhz"; hertzPosition=6;}  
 else{increment = 10; hertz = "10 Hz"; hertzPosition=5;};  
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(hertzPosition,1);
  lcd.print(hertz);
  delay(250); // Adjust this delay to speed up/slow down the button menu scroll speed.
};



void showFreq(){
   millions = int(rx/1000000);
   hundredthousands = ((rx/100000)%10);
   tenthousands = ((rx/10000)%10);
   thousands = ((rx/1000)%10);
   hundreds = ((rx/100)%10);
   tens = ((rx/10)%10);
   ones = ((rx/1)%10);
   lcd.setCursor(0,0);
   lcd.print("                ");
  if (millions > 9){lcd.setCursor(1,0);}
  else{lcd.setCursor(2,0);}
   lcd.print(millions);
   lcd.print(".");
   lcd.print(hundredthousands);
   lcd.print(tenthousands);
   lcd.print(thousands);
   lcd.print(".");
   lcd.print(hundreds);
   lcd.print(tens);
   lcd.print(ones);
   lcd.print(" Mhz  ");  
};

void loop() {
 if (rx != rx2){    
       showFreq();
       sendFrequency(rx);
       rx2 = rx;
     }
     
 buttonstate = digitalRead(A0);
 if(buttonstate == LOW) {
       setincrement();        
   };
 
}



Moderator edit:  Italic tags (?) swapped for code tags. (AWOL)

strykeroz

Hi

I expect you're not going to be happy with my answer, but here it is
Code: [Select]
#include <Rotary.h>

Library names are case sensitive.  Your code compiles once you make that change.

All the best!
Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
                  First of all my sincere thanks for your time. I tried it but no luck .It is not taking (it is not turning brown). I am wondering why it is not functioning. Any other thing you can think of ? All comments are welcome even though it may not immediately solve the problem. Once again thanks for your efforts.

With regards,
(nivar)

strykeroz

Hi nivar

Without your hardware setup the more info you can provide the better.  Do the displayed messages on the LCD do what you expect? And have you added debugging messages to output what is going on under the hood that will help a great deal too.

Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
              Once again thanks for the prompt response. I think by LCD you mean the LCD display I am trying to use with Arduino. As I have mentioned in my original post above I was not able to load the program to the Arduino IDE so there is no question of reading the LCD . What ever error messages I got during the loading process I have included in the above post . I think what you were mentioning in the last sentence is this . You may kindly let me know.

With regards,
(nivar)

strykeroz

Hi nivar

I don't understand by what you mean by "it is not turning brown".  Can you explain this?

I can load your code with the change to the library name on an Arduino here without any errors.  What error are you seeing now?

Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
                  Thanks for the reply. I am glad to know you can load the code without any errors. By "turning brown " what I meant was that if the library is active in the sketch it turns brown otherwise it remains black. In my case it remains as it is without any color change and the sketch is not able to load . I again tried to load it and again get the same 3 error messages (reproduced below again ). I request you to kindly reproduce the code you successfully loaded.

Step 11.error - 'Encoder' does not name a type

Step 40 in function 'void_vector_5()';
       error -  'r' was not declared in this scope   

Step 42 error -  'DIR_CW' was not declared in this scope
code"

Once again thanks for your time .

with regards,
(nivar)

strykeroz

Just change the one line I quoted in my first post and it loads without error.

Cheers ! Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
                      Nice to see your reply so fast. I think you want me to change the  "rotary" to  "Rotary"  as the only change in my program? I have done it many times without luck. I think I have to load it on another computer and see ? Thanks for your time.

With regards,
(nivar)

strykeroz

Hi,

If that change doesn't solve it, do both the examples for the Rotary library work?  If not, it's likely you've not got your Rotary library installed correctly.

I just copied your code from the first post, changed rotary.h to Rotary.h and compiled.  Screen cap attached.

Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
               Further to your last posting , I tried to edit the "Rotary" files but I am not fully successful in it. I edited the "Rotary.h" and "Rotary.cpp" files and everything appears to be fine with it. But when I go back to my  program and try to run it, still same old error messages flashes and I am not able to load it. So what I request you is if possible please tell me how to do the editing of files in the Arduino IDE ? Thanks in advance for your time.

With regards,
(nivar)

strykeroz

Hi nivar

There is no need to edit the library files at all.  If you edit your own program and change the include line to have a capitalised R in Rotary.h and it is not working, your Arduino IDE is not seeing the Rotary libary to use when compiling.

To test this, load one of the rotary library examples (from the menu, take File / Examples / Rotary / Polling) and compile that.  If it fails to compile you know your Rotary library is not correctly installed*.  To check, take the menu option Sketch / Import Library and you should see Rotary in the list.  Unfortunately if, like me, you have a stack of libraries installed, there is no scrollbar on this menu and you may not see the full list.  With a new installation of the Arduino IDE you should see it though.  If it's not there, you need to copy the Rotary library directory under your Arduino libraries folder.  If you're using Windows this will most likely be C:\Users\<your user name>\Documents\Arduino\libraries.  After you copy the library folder in there, under windows you'll have a new folder C:\Users\<your user name>\Documents\Arduino\libraries\Rotary containing an examples subfolder, keywords.txt, README.md, Rotary.cpp & Rotary.h

Exit all Arduino IDE windows and restart the IDE (it indexes libaries on startup).

Repeat the tests above and it should now work.  

All the best,
Geoff

* in fact if the library isn't installed, these examples won't exist in the menu !!
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Hi Geoff,
             Since seeing your last post I was trying to install the "Rotary" code in the "sketch" folder of the IDE without much success!. As per your post I opened C/users/my name/documents/arduino/libraries/Rotary . I can see all the files mentioned by you in the "Rotary". But when I opened the IDE / "sketch/import library " I can see the name "Rotary" in it but when I click it open ,it is totally  empty (only the name is there). All my efforts to install it properly is yet to succeed.  I am wondering whether you can post your "Rotary" code as seen in your IDE sketch library. Hope I am not bothering you too much.
With regards,
(nivar) 

strykeroz

Hi,

No problems at all.  Did you download the Rotary library files from this github repository?  That's where all the files I listed above came from.

Cheers !
Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

nivar

Yes  same file I tried . But still the problem persists.

(nivar)

Go Up