Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Slowing down rotary encoder using interrupts on: May 09, 2012, 07:02:06 pm
Thank you all for your fast replys and great advise.  I now have it running alot smother and more fine control smiley

The quickest thing you can try is to change the interrupt mode, that will change the step speed in half. You will have to see if that is improvement enough or not.

I Did this and it did help but found it was still little fast.


Quote

What you could do is divide the incoming pulses, simply by counting them, and only outputting a pulse every three or four interrupts.
Don't forget to reset the counter.

I did this aswell and found combination of the too did the trick nicely.

im not sure if how I went about doing it in my interrupt code is best method.  any feedback would be great




Code:
//************************************Rotary Encoder**************************************
void doEncoder(){

  if (digitalRead(encoder0PinA) == HIGH) {   // found a low-to-high on channel A
    if (digitalRead(encoder0PinB) == LOW) {  // check channel B to see which way
      // encoder is turning

      Rotate = Rotate;                // CCW
      
    }//end  if (digitalRead(encoder0PinB) == LOW)
    else {
      Rotate = Rotate;                 // CW
    
    }//end else
  }//end if (digitalRead(encoder0PinA) == HIGH)
  else                                        // found a high-to-low on channel A
  {
    if (digitalRead(encoder0PinB) == LOW) {   // check channel B to see which way encoder is turning  
      Count ++;
      if (Count >= 5) {
        Rotate = Rotate +jump;        // CW
        Count =0;
      }//end Count if
      
          }//end if

    else {
      Count ++;
      if (Count >= 5) {
        Rotate = Rotate -jump;         // CCW
        Count =0;
      }//end Count if



    }//end else
  }//end else if (digitalRead(encoder0PinB) == LOW

}//end subroutine


Moderator edit: corrected tags (hopefully)
2  Using Arduino / Project Guidance / Slowing down rotary encoder using interrupts on: May 09, 2012, 01:27:33 am
Hello,

I Am currently building a DDS Frequency Generator using an Arduino and a AD9835 http://arduino.cc/forum/index.php?topic=67958.0 I got from Spark fun.

I am using a 3x4 matrix keypad to set the output frequency and a rotary encoder for fine tuning..  I have most of this working except the rotary encoder is way to sensitive.  I am using hardware debouncing found here http://arduino.cc/playground/Main/RotaryEncoders#Debounce and this works great in that the decoder increments in single steps.  My problem is that I am using interrupts to control the rotary encoder and am using a large dial type knob on the encoder and find it very hard to make small adjustments to it.  When I spin at a reasonable pace the frequency is going up too fast.  I have never used interrupts in the past but read that there is no way to put in a delay in the code.  how do I go about slowing down the interrupts so it only reads every 2nd or 3rd pulse from the encoder?  Can this be done in softwre or do I need to use some kind of hardware methord to slow it down.

I have attached my encoder and keypad section of the code below.  any help or comments would be appreciated

  
Code:
/**
 * sinusoid Frequency generator.
 *
 * This program produces a sinusoidal signal using the AD9835 IC
 */

// variables will change:
long Rotate=10000;
long Frequency =0;
int jump = 1;
long num = 0;
//*********************************************************LCD Setup Start******************************************
#include <SoftwareSerial.h>

#define txPin 5

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

//*************************************AD9835 setup*************************************

#include <SPI.h>
#include "AD9835.h"

//setup Keypad Pins\

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'                                                              }
  ,
  {
    '4','5','6'                                                              }
  ,
  {
    '7','8','9'                                                              }
  ,
  {
    '*','0','#'                                                              }
};
byte rowPins[ROWS] = {
  48, 46, 44, 42}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  40, 38, 36}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// We begin by creating the AD9835 object with the pin assignments
// that are used.  If another pinout is used, this must be
// modified.

//First We must first set up all of our DDS AD9385 output pins.
AD9835 dds(
13, // FSYNC
9, // SCLK
8, // SDATA
12, // FSEL
11, // PSEL1Arduino Serial USB Board
10, // PSEL0
50000000 // hzMasterClockFrequency (50MHz)
);


//***********************************Encoder setup Start**********************************
#define encoder0PinA  2
#define encoder0PinB  4


  //*************************************Encoder Setup**************************************
  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor
  attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2

}//end setup

void loop(){



  while(1)
  {
    InputKeys();
    SerialSend();


//*************************************Keypad Setup***************************************
void InputKeys(){

  char key = keypad.getKey();
  if (key){
    switch (key) {
    case '#':
      Frequency = num ;//Set Frequency to number entered
      dds.setFrequencyHz(0, (Frequency)); //Send new Frequency to DDS IC
      dds.selectFrequencyRegister(0);

      // Without modulation the choice of phase offset does not matter,
      // but we set it to zero for good measure.
      dds.setPhaseDeg(0,0);
      dds.selectPhaseRegister(0);
      Serial.println("---------------------");
      Serial.println("the frequency is");
      Serial.print(Frequency);
      Serial.print(" Hz");
      Serial.println("");
      Serial.println("--------------------");
      num=0;
      clearLCD();
      delay (100);
      break;

    case '*'://clear input
      num=0;
      clearLCD();
      break;

    default:
      key=key-'0'; //convert from Char to integer otherwise will be out by 48
      num =(num*10 + key); //move left 1 decimal place and enter next digit
      //Serial.println(num); //print number
      Serial.println(num); //print number
      break;
    }//end switch

  }//end if
  delay(10);

}//end keypad subrutine


//************************************Rotary Encoder**************************************
void doEncoder(){


  if (digitalRead(encoder0PinA) == HIGH) {   // found a low-to-high on channel A
    if (digitalRead(encoder0PinB) == LOW) {  // check channel B to see which way
      // encoder is turning


      Rotate = Rotate;                 // CCW
    }//end  if (digitalRead(encoder0PinB) == LOW)
    else {
      Rotate = Rotate;                 // CW
    }//end else
  }//end if (digitalRead(encoder0PinA) == HIGH)
  else                                        // found a high-to-low on channel A
  {
    if (digitalRead(encoder0PinB) == LOW) {   // check channel B to see which way
      // encoder is turning  
      Rotate = Rotate + jump;        // CW
    }//end if

    else {
      Rotate = Rotate - jump;         // CCW
    }//end else
  }//end else if (digitalRead(encoder0PinB) == LOw

}//end subroutine


void SerialSend(){

  //***************************************DDS STUFF**************************************
 
  //clearLCD();
  
Frequency =  Rotate;
  
  // Start the dds Libary
  dds.begin();
  // We then set the board to produce a signal.
  dds.setFrequencyHz(0, (Frequency));
  dds.selectFrequencyRegister(0);

  // Without modulation the choice of phase offset does not matter,
  // but we set it to zero for good measure.
  dds.setPhaseDeg(0,0);
  dds.selectPhaseRegister(0);

  // Finally, we turn on the IC.
  dds.enable();

 
}






3  Using Arduino / Project Guidance / Re: arduino controled relays on: April 11, 2011, 06:38:51 am
How do I chain the shift registers,  I can connect the clock and Latch together, do I do the same with the data or does this need to be separate?
4  Using Arduino / Project Guidance / arduino controled relays on: April 11, 2011, 03:11:54 am
Hello,

I have a project were I need to switch 13 relays.  I read an article that mentioned a mentioned of using shift registers to cut down the number of pins required. As I really don't know anything about this thought I would get you smart people to check over my schematic. The circuit uses a ULN2003AD Darlington array and a 74HCT595D shift register.  Am I doing this right? is there a better way to achieve this?
also do I need to use diodes across my relays I took these off as there are Diodes in the Darlington array.

Thanks in advance for all your help
5  Using Arduino / Displays / Re: Change LCD Pins on Mega on: February 20, 2011, 01:05:59 am
Thank you so much for your help.  It works great smiley
6  Using Arduino / Displays / Re: Change LCD Pins on Mega on: February 20, 2011, 12:04:32 am
Thanks for the fast reply :-D

How Do I change the pin definitions in the LCD library,  I cant find an reference to pin numbers in the LCD lib files.  I tried moving the encoder and it wont work, think its something to do with the way it uses interrupts,  I used the standard encoder code from the playground.  Sorry for all the questions but I am still new to this.  Thanks for your help ? 
7  Using Arduino / Displays / Change LCD Pins on Mega on: February 19, 2011, 10:26:53 pm
Hello I have a arduino Mega board that I am using to control my preamp.  I just started learning arduino and programing and need bit of help.  I have a 4x20 LCD HD44780 screen and I want to change the default pin outs on the arduio to run it.  I have heaps of spare pins as Im using a mega.  It wants to run on pins 12, 11, 5, 4, 3, 2. these pins are in use for something else (rotary encoder and pga2310 volume controller)   How do I change the pin outs??

Thank you in advance for your help
8  Forum 2005-2010 (read only) / Interfacing / Re: GLCD Menu on: January 24, 2011, 03:23:33 am
Thanks for this,  Think im little out of my depth with these graphic LCD so decided to stick to a 4x20 character LCD Display for now.
9  Forum 2005-2010 (read only) / Interfacing / GLCD Menu on: January 23, 2011, 08:53:38 am
Hello everyone

I am new to the world of microcontrolers. I am working on a HIFI Pre AMP to run a power Amp I built few years ago.  I got an Arduino Mega off ebay that came with a ks0108 128*64  GLCD screen.  I want to create a menu to select different sources (CD DVD Radio etc) and use a rotary encoder to select items from the menu.  I have found lots of sample code for doing this with a standard 20x2 LCD,  but nothing for using my big GLCD.  Can someone please point me in the right direction. Also I would like to create a volume level display and remote control.  This is a sample of what I would like to do, only on bigger screen.  youtube.com/watch?v=EZigza0sSOc

I have been thinking it would also be fun to create a spectrum analyzer on this display.

Thanks in advance for all your help
10  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino controled HIFI Preamp on: January 23, 2011, 05:26:34 am
Sorry don't like bumping post's, but could really use some help
11  Forum 2005-2010 (read only) / Frequently-Asked Questions / Arduino controled HIFI Preamp on: January 22, 2011, 10:05:34 am
Hello everyone

I am new to the world of microcontrolers. I am working on a HIFI Pre AMP to run a power Amp I built few years ago.  I got an Arduino Mega off ebay that came with a ks0108 128*64  GLCD screen.  I want to create a menu to select different sources (CD DVD Radio etc) and use a rotary encoder to select items from the menu.  I have found lots of sample code for doing this with a standard 20x2 LCD,  but nothing for using my big GLCD.  Can someone please point me in the right direction. Also I would like to create a volume level display and remote control.  This is a sample of what I would like to do, only on bigger screen.  youtube.com/watch?v=EZigza0sSOc

I have been thinking it would also be fun to create a spectrum analyzer on this display.

Thanks in advance for all your help
Pages: [1]