1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Problem with digital Potentionmeter controling a 555 Timer

Discussion in 'Robotics & Mechatronics' started by anilson1, Mar 26, 2016.

  1. anilson1

    anilson1 New Member

    Joined:
    Apr 26, 2010
    Messages:
    3
    Likes:
    0
    hi,

    I am trying to build a simple project which I use a "PIC16F88" communicating through (SPI) with a digital potentiometer DS1267-10 to control the oscillation of a timer 555

    Here is the code:

    Code (c):


       unsigned char bou[9];
     
    void sendDATA()
    {
       unsigned char counter = 0;     //Declare and initialize the counter
     
       RB3_bit = 1;                   //Initiate communication through RST
       Delay_us(50);

       while(counter<9)
       {
             if(RB4_bit == 0)
             {
                counter = counter + 1;   //counting pulse on the low
                RB2_bit = bou[counter];  //Send Data
                Delay_us(30);
             }

          RB4_bit = ~ RB4_bit;        //toggle the clock
          Delay_us(50);                //Duty cycle
       }
     
       RB4_bit = 0;
       RB3_bit = 0;                   //Stop communication through RST
    }


    void main(){

       ANSEL = 0;           // pins are configured as digital I/O

       TRISA = 0xFF;           // set PORTA direction to be input
       TRISB = 0x00;           // set PORTB direction to be output

       PORTB = 0;

       do{
            if(RA2_bit == 0)
            {
              bou[0]=1;
              bou[1]=1;
              bou[2]=1;
              bou[3]=0;
              bou[4]=1;
              bou[5]=0;
              bou[6]=1;
              bou[7]=1;
              bou[8]=0;
           
              sendDATA();
            }

            if(RA3_bit == 0)
            {
              bou[0]=0;
              bou[1]=0;
              bou[2]=1;
              bou[3]=0;
              bou[4]=0;
              bou[5]=1;
              bou[6]=0;
              bou[7]=0;
              bou[8]=0;
           
              sendDATA();
            }
       }while(1);
    }
     

    The problem is: the oscillator only oscillates at one frequency, by pressing the buttons it does not chance the oscillation speed. Not sure if the problem is on the circuit or on the code. Any idea?
     

    Attached Files:

    Last edited by a moderator: Mar 27, 2016
  2. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    8,778
    Likes:
    1,148
    Location:
    Cardiff, Wales
    You're using only the H0,L0,H1,L1 pins of the dual pot. The resistance between those is fixed. You need to use a wiper pin (W0 and/or W1).
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,422
    Likes:
    799
    Location:
    Rochdale UK
    Your code only has 8 bits.... There should be 17 bits SB, W1bits, W2bits..

    I assume you are trying to use stacked... You need to redraw your circuit as well..

    Here is the code for single wiper..
    Code (c):

    unsigned char bou[17];

    void sendDATA()
    {
      unsigned char counter = 0;  //Declare and initialize the counter

      RB3_bit = 1;  //Initiate communication through RST
      Delay_us(50);

      while(counter<17)
      {
      if(RB4_bit == 0)
      {
      counter = counter + 1;  //counting pulse on the low
      RB2_bit = bou[counter];  //Send Data
      Delay_us(30);
      }

      RB4_bit = ~ RB4_bit;  //toggle the clock
      Delay_us(50);  //Duty cycle
      }

      RB4_bit = 0;
      RB3_bit = 0;  //Stop communication through RST
    }


    void main(){

      ANSEL = 0;  // pins are configured as digital I/O

      TRISA = 0xFF;  // set PORTA direction to be input
      TRISB = 0x00;  // set PORTB direction to be output

      PORTB = 0;

      do{
      if(RA2_bit == 0)
      {
      bou[0]=0;
      bou[1]=1;
      bou[2]=1;
      bou[3]=1;
      bou[4]=1;
      bou[5]=1;
      bou[6]=0;
      bou[7]=0;
      bou[8]=0;
      bou[9]=0;
      bou[10]=0;
      bou[11]=0;
      bou[12]=0;
      bou[13]=0;
      bou[14]=0;
      bou[15]=0;
      bou[16]=0;

      sendDATA();
      }

      if(RA3_bit == 0)
      {
      bou[0]=0;
      bou[1]=1;
      bou[2]=1;
      bou[3]=0;
      bou[4]=0;
      bou[5]=0;
      bou[6]=0;
      bou[7]=0;
      bou[8]=0;
      bou[9]=0;
      bou[10]=0;
      bou[11]=0;
      bou[12]=0;
      bou[13]=0;
      bou[14]=0;
      bou[15]=0;
      bou[16]=0;

      sendDATA();
      }
      }while(1);
    }
     
    And the circuit.... NOTE 555 ouput needs to go to the top of the wiper as you are trying to keep a 50% duty cycle..

    upload_2016-3-27_12-7-30.png
     
    Last edited: Mar 27, 2016
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,062
    Likes:
    153
    Location:
    San Diego, Ca
    And that is the way a schematic should look. Ian, I don't use the PIC parts, but couldn't he just use the on-board PWM, and not need the digital pot, or 555?
     
    • Like Like x 1
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,422
    Likes:
    799
    Location:
    Rochdale UK
    Not even that.... Just a bit banged output with variable delays.... Any pic would do it!! But I think this is an exercise..
     
  7. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,062
    Likes:
    153
    Location:
    San Diego, Ca
    Yeah, you are probably right:)
     
  8. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,005
    Likes:
    532
    Location:
    Peterhead, Scotland
    I do agree, it is a curious thing to do, using a microcontroller to set the frequency of a 555.
    However, as a didactic exercise there are a lot of useful things to learn while doing this.

    JimB
     
  9. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,062
    Likes:
    153
    Location:
    San Diego, Ca
    It actually sounds like it should be a little fun.
     
  10. anilson1

    anilson1 New Member

    Joined:
    Apr 26, 2010
    Messages:
    3
    Likes:
    0
    Hi guys,

    Thank you all for your input and help.

    True, this is just an exercise eventually I will remove the timer 555 and connect the pic and digital pot to a motor controller which is controlled by a variable resistor. The timer is just a way to see how the resistance changes, main focus is on the digital pot using a microprocessor (pic).

    I forgot to mention the configuration of the digital pot DS-1267-10 is stack, which puts in series the two resistances inside the chip and the output is on the Sout (pin 13) instead of using the W0 or W1. The datasheet is not very clear but I think it says that for stack configuration it uses 9 bits of resolution.


    upload_2016-3-28_0-13-39.png
     

    Attached Files:

  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,422
    Likes:
    799
    Location:
    Rochdale UK
    Then change bout[0] to a 1.... The last 16 bits will be for both pots... swap out w0 for Sout connect L0 to H1 and L1 to Sout and you are done...
     

Share This Page