View previous topic :: View next topic |
Author |
Message |
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Tue May 10, 2011 4:06 am |
|
|
Hi
I need a program to control the speed and direction of a stepper motor based on the feedback signals I receive from two proximity sensors. I have necessary hardware. I have a pic development board with PIC16F72 as micro-controller. Port B is connected to ULN2803 to drive the stepper motor. I need two countdown timers to control the stepper motor. While the stepper is rotating, based on the proximity sensor's output, the motor has to rest on the either sides for predetermined time(which is adjustable on every startup of the unit). One of the times should be in seconds and other is in minutes. I have two common anode seven segment displays and three push to on switches for serving this purpose. I have connected the stepper motor to pins B1,B2,B3,B4; two seven segment displays to C1,C2,C3,C4,C5,C6,C7; three push to on buttons to A0,A1,A2;feedback from proximity sensors to A3,A4; and two Vcc pins of the two seven segment displays to A5 and C0 and are given a pull up to +5V via 10K resistor. The circuit uses a 4MHz oscillator. Please help me. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed May 11, 2011 3:48 pm |
|
|
thats a start
got a schematic that shows how you have it all connected
especially to your MOTOR windings ?
do you at least have a code shell that outlines what you actually want to do
and the approach to driving the stepper as a response ?
i don't think you will find anyone who has the ability to do such a program who will write for you from scratch.
to get help you have to output some sign of real effort on your part FIRST
that demonstrates you understand the problem you have set for yourself
and have at least a CLUE about how to go about it.
from there - you can get help |
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Thu May 12, 2011 1:29 am |
|
|
Hi
I am good at programming in c but not for microcontrollers. Following description gives a flow of how the circuit should operate.
After the circuit is switched on:
1. Able to set two countdown timers t1 and t2
a. Display t1 at the start up (t on the left 7-segment display(7SD) and 1 on the right 7-segment display(7SD) (here after referred to as 7SDL and 7SDLR respectively))
b. Then press enter push to on switch(here after referred to as PSE) connected to RA0 which allows us to change the time
c. Time is changed using increment and decrement push to on switches (here after PSI and PSD respectively))
d. Press PSE to set t1
e. t2 is displayed on the 7SDs(t on 7SDL and 2 on 7SDR)
f. Time is changed using increment and decrement push to on switches (here after PSI and PSD respectively))
g. Press PSE to set t2
2. Now Stepper Motor(SM here after) which is connected to port B ( B1,B2 to one coil (black and blue wires of the SM (green and red wires of SM in that order)) and B3, B4 to another coil (green and red wires of SM in that order)) starts rotating in one direction, say clock wise (CW) (which is same on each start-up of the circuit).
3. During rotation, a knob which is connected to the shaft of the SM now comes in proximity of the first proximity sensor (PS1) and corresponding output (OP1) is generated. This output is given at RA3. Now the SM halts at this position for t1 i.e., no output on B1-B4.
4. After t1 SM starts rotating in reverse direction i.e., anti clock wise (ACW)
5. During rotation knob comes in the proximity of the second proximity sensor (PS2) and corresponding output (OP2) is generated. This output is given at RA4. Now the SM halts at this position for t1 i.e., no output on B1-B4.
6. After t2 SM starts rotating CW again
7. Steps 3 through 6 repeat till the circuit is on.
Please help me with the programming. The micro controller I am using is PIC16F72. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Thu May 12, 2011 1:59 am |
|
|
Are you using PCM ??
Is the hardware ready ?? How do you intend to test it ??
The project that you have described is complicated for a beginner. You need to first learn the basics of setting up timers, handling push buttons, display segments and stepper motor etc.
I suggest you work on a simple projects first, like blinking a LED, using a push button to switch On and OFF a LED etc.
Then you can move on to more complicated ones like driving a stepper motor , controlling display segments etc.
thanks
a |
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Thu May 12, 2011 3:17 am |
|
|
The hardware is ready. Previously I bought a stepper driver and timer separately. But when I combined them to operate it is not functional. So I am planning to do it on my own. Please give me some basic programs that you have suggested. I need to complete the programming by this weekend. I will be testing the code by directly dumping it into controller and using the hardware. I don't think I will use PCM. I think all the signals I use are digital. Do you think it will be necessary for my program. Please let me know.
Thank you in advance |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Thu May 12, 2011 5:29 am |
|
|
FYI, PCM here, on this forum, means the version of the CCS C compiler not Pulse Code Modulation. CCS has many compilers (PCM, PCD, PCH, etc.)
There is an example of a stepper motor program in the examples folder, which is a good place to start. Actually look at all of the examples, most of what you want to do can be found there.
Just start off small,breaking the big program into smaller parts. Motor control, switch inputs, LED display tasks. That way you'll have working 'sub programs' that you can build on.
Be aware that if using MPLAB for development, that it defaults the build configuration to 'debug'. This must be changed to 'release' and then you must recompile(F10) , then download the program into your PIC. Failure to do so will not allow your PIC to run right. There is a 'patch' for MPLAB v.8.66 to change the default to 'release' permanently. |
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Thu May 12, 2011 1:02 pm |
|
|
Please tell me whether the connections I have given are correct. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Thu May 12, 2011 6:25 pm |
|
|
You're the one designing the project, so it's up to you ...
..however..
I suggest you read/look at the examples that CCS gives.
EX_LED.C for LED wiring and testing...
EX_STEP.C for stepper motor control..
EX_PBUTT.C for push button/switch interface
In each program, you'll have to change the PIC pin assignments, but these programs are a GREAT starting point !!Once you've cut code for your project, report back with your test code and maybe others will help out. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu May 12, 2011 6:32 pm |
|
|
ONE CLEAR schematic beats hundreds of lines of circuit description....
honestly - it is just too much work for me to think about your problem
if you don't have a schematic or any code of your own to show that
you are serious and have enough innate skill and experince to
at least dig in and TRY to solve the code issues yourself
sorry |
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
Re: RE: |
Posted: Fri May 13, 2011 7:49 am |
|
|
Are you from IISc?
arunb wrote: | Are you using PCM ??
Is the hardware ready ?? How do you intend to test it ??
The project that you have described is complicated for a beginner. You need to first learn the basics of setting up timers, handling push buttons, display segments and stepper motor etc.
I suggest you work on a simple projects first, like blinking a LED, using a push button to switch On and OFF a LED etc.
Then you can move on to more complicated ones like driving a stepper motor , controlling display segments etc.
thanks
a |
|
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Fri May 13, 2011 3:35 pm |
|
|
Hi
I have MPLAB IDE v8.36, and PICKIT-2 programmer and debugger. I want to program PIC16F72 using that. Under 'select device' under 'configure' option, I have selected he PIC16F72. I am not able to select the programmer pickit-2 as it not highlighted. Please tell me what to do. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Fri May 13, 2011 5:57 pm |
|
|
Also be aware that the MPLAB default for 'build configuration' is 'debug' and MUST be changed to 'release' then recompile(F10) in order to et correct code to be downloaded into your PIC.
There is a 'patch' to change this default to 'release'. |
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Sun May 15, 2011 12:02 pm |
|
|
I have tried that but of no use. Shall you give me any other suggestion.
Thanks
Vikram
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 15, 2011 12:37 pm |
|
|
You're right. I think Microchip lied. The link that I posted says they
support the 16F72 with Pickit 2 in vs. 8.66. But then if I go to the Select
Device screen in MPLAB vs. 8.66, it says no support for Pickit 1 and
Pickit 2. Only Pickit 3 is supported.
My advice is to choose a different PIC. Use the Configure / Select Device
screen in MPLAB to see what devices are really supported for Pickit 2.
Then buy a PIC that is supported. |
|
|
|