potentiometer help

Discussion in 'General Electronics Chat' started by cassity69, Dec 18, 2013.

  1. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    hello new to the forum
    im trying to interface a variable resistor with a PIC and a stepper motor i already have the stepper motor moving forwards with a programme i made but i have no idea how to interface the POT can anyone help?
    im using C programming and the stepper is 5v
    IC darlington driver
    POT 10 K B
    the idea is that the POT will act as an accellerator to the stepper motor
    any help would be brilliant
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    You haven't given much information here (part numbers, schematic, source code) but if you are generating the steps with the PIC, read the pot with the PIC ADC and adjust your step timing accordingly. If the PIC does not have an ADC, there are various, ugly other ways..
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,550
    2,373
    There are App notes for stepper control on the Picmicro site, do you intend input the pot directly to the analogue input of the pic?
    As IIRC they have an exact example.
    Max.
     
  4. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    Do 99% of the people in the world not know about search engines?
    Step 1: go to www.google.com
    Step 2: enter your search terms.. like "PIC potentimeter stepper"
    and voila.. first hit here..
    http://hades.mech.northwestern.edu/index.php/Stepper_motor_control_with_the_PIC

    Also I've found that the "arduino" folks have way more tutorials (or just easier to find) than the PIC folks
    The code is obviously different but the basics are still the same.. Read pot with ADC.. adjust code based on ADC reading..
     
  5. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    i am generating steps with the PIC yes and the pic does have a ADC ( port A ) so i need to connect the potentiometer to this right ?
     
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    Read the link I posted along with the other peoples answers to find that answer to your question.
    Try to walk before you try to run and just trip over your feet...
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    Depending on what you are attempting to do you might not need a stepping motor.
    There is such a thing as a digital pot that you can control digitally.
     
  8. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    THIS IS MY STEPPER MOTOR CODE ( WORKING )

    #pragma config OSC = HS //set osc mode to HS high speed clock
    #pragma config WDT = OFF // set watchdog timer off
    #pragma config LVP = OFF // Low Voltage Programming Off
    #pragma config DEBUG = OFF // Compile without extra Debug compile Code
    /* Include Files */
    #include <p18f4520.h> // Device used is the PICF4520
    #include <delays.h> // Include the delays routines
    unsigned char STEP1 = 0xAA; // Assign hex value AA to Step 1
    unsigned char STEP2 = 0x66; // Assign hex value 66 to Step 2
    unsigned char STEP3 = 0x55; // Assign hex value 55 to Step 3
    unsigned char STEP4 = 0x99; // Assign hex value 99 to Step 4
    void main (void)
    {
    /*Set PORT D as Digital Outputs */

    LATD = 0x00; // Initialise Port D
    TRISD = 0x00; // Configure Port C as O/P

    while (1) // run forever
    {
    LATD = STEP1;

    Delay10KTCYx(6); // Short delay here so we can see output
    LATD = STEP2;
    Delay10KTCYx(6); // Short delay here so we can see output

    LATD = STEP3; // write the value of D (55) to Port C
    Delay10KTCYx(6); // Short delay here so we can see output
    LATD = STEP4;
    Delay10KTCYx(6); // Short delay here so we can see output


    }
    }
     
  9. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    AND THIS IS THE SAMPLE ADC CODE WHICH I DONT REALLY UNDERSTAND


    #pragma config OSC = HS /*set osc mode to HS */
    #pragma config WDT = OFF /* set watchdog timer off */
    #pragma config LVP = OFF /* Low Voltage Programming Off */
    #pragma config DEBUG = OFF /* Compile without extra Debug compile Code */
    #include <p18f4520.h> /* Device used is the PICF452 */
    #include <adc.h>
    #include <stdlib.h>
    #include <delays.h>
    void main (void)
    {
    /*Set PORT B as Digital Outputs to display only the 8 LSB ADC values*/

    TRISB = 0x00; /* Configure Port B as O/P */
    TRISA = 0xFF; /* Configure Port A as i/Ps for ADC */
    TRISD = 0X00;
    /* Configure the ADC */
    /* The following configure the ADC module operational mode */
    /* OpenADC configures the operation of the ADC with a number of arguments*/
    /* ADC_FOSC selects the ADC clock sourceand has a number of set values */
    /* ADC_RIGHT_JUST select ADC result justification */
    /* ADC_0_TAD sets the A/D acquisition time select */
    /* ADC_CH0 select Channel 0 */
    /* ADC_INT_OFF Interrupts are disabled */
    /* ADC_VREFPLUS_VDD set ADC + reference voltage configuration to VDD */
    /* ADC_VREFMINUS_VSS set ADC - reference voltage configuration to VSS */
    /* 0b1011 are the A/D control Reg 1 config bits setting the reference and function of port bits */
    OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011);
    SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */
    ConvertADC( ); /* start A/D conversion */
    while(BusyADC( )); /* wait for completion */
    LATB = ADRESL;
    LATD = ADRESH;
    CloseADC( );
    }
     
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ....then let's take a look at it.

    Also, there it's no need for all caps, we can hear you just fine without them.

    Code ( (Unknown Language)):
    1. #pragma config OSC = HS     /*set osc mode to HS */
    2. #pragma config WDT = OFF    /* set watchdog timer off */
    3. #pragma config LVP = OFF    /* Low Voltage Programming Off */
    4. #pragma config DEBUG = OFF  /* Compile without extra Debug compile Code */
    5. #include <p18f4520.h>        /* Device used is the PICF452 */
    6. #include <adc.h>
    7. #include <stdlib.h>
    8. #include <delays.h>
    9. void main (void)
    10. {
    11. /*Set PORT B as Digital Outputs to display only the 8 LSB ADC values*/
    12.  
    13. TRISB = 0x00;       /* Configure Port B as O/P */
    14. TRISA = 0xFF;     /* Configure Port A as i/Ps for ADC */
    15. TRISD = 0X00;
    16.  
    17. OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011);
    18.  SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the  */
    19.  ConvertADC( );  /* start A/D conversion */
    20.  while(BusyADC( ));  /* wait for completion  */
    21.     LATB = ADRESL;
    22.     LATD = ADRESH;
    23.   CloseADC( );
    24. }
    OpenADC is a function that configures the ADC according to the options passed to it (all those comments I removed).

    SetChanADC sets the channel of the ADC that will be converted (in this case, it will use AN0).

    ConvertADC tells the ADC module to perform the conversion.

    Code ( (Unknown Language)):
    1. while(BusyADC( ));
    polls the go/done bit to wait until a conversion is done (the result will be in ADRESH and ADRESL, in a manner consistent with the justification set in the OpenADC function)

    Code ( (Unknown Language)):
    1.  LATB = ADRESL;
    2.     LATD = ADRESH;
    This just puts the ADC result on the output ports (attach LEDs to view the result)

    Code ( (Unknown Language)):
    1.  CloseADC( );
    Turnoff the ADC module

    You need not use these functions, you can read the datasheet and set the values in the registers directly...

    ...and please use code tags (button that looks like "#") when posting code...
     
  11. cassity69

    Thread Starter Member

    Dec 18, 2013
    37
    0
    ok thanks alot tshuck
    im having to leave the lab now
    ive finally wired the hardware together correctly using port a on the pic i actually understand
    i will look into what you have wrote tommorow at 10
    thanks again
     
Loading...