potentiometer help

Thread Starter

cassity69

Joined Dec 18, 2013
37
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
 

JohnInTX

Joined Jun 26, 2012
4,787
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..
 

MaxHeadRoom

Joined Jul 18, 2013
30,881
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.
 

mcgyvr

Joined Oct 15, 2009
5,394
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..
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
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 ?
 

mcgyvr

Joined Oct 15, 2009
5,394
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 ?
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...
 

MrChips

Joined Oct 2, 2009
35,296
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.
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
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


}
}
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
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( );
}
 

tshuck

Joined Oct 18, 2012
3,534
AND THIS IS THE SAMPLE ADC CODE WHICH I DONT REALLY UNDERSTAND
....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.

Rich (BB code):
#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;

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( );
}
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.

Rich (BB code):
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)

Rich (BB code):
 LATB = ADRESL;
    LATD = ADRESH;
This just puts the ADC result on the output ports (attach LEDs to view the result)

Rich (BB code):
 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...
 

Thread Starter

cassity69

Joined Dec 18, 2013
37
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
 
Top