Suggestion for program flow

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Suggestion for program flow

Post by Bobw »

I am writing a program to control the direction of a motor either CW or CCW.

1) User (via POT) sets the desired position. (This part works great)
2) "GO" button is pressed. (Works)
3) Decision DO I have to move CW or CCW. <Works with question>
4) Move until new position is reached.
5) Turn off motor.
6) Go back to step 1

My questions is, should I have a separate loop for CW movement and another for CCW movement?
The feed back is given by a quadrature encoder on the motor shaft. (yet to be programmed)
right now I have one loop for movement both CW or CCW, but since it will also have to count pulses from the encoder I am worried about dropping a few while going through such a long loop.
Each one has to count the pulses, do the math to display degrees of rotation (320 pulses =1°, look for a "STOP" button to be pressed, or self stop when the "SET" position and the "ACTUAL" position match, and finally store the new "ACTUAL" value in non volatile memory for retrieval when the program starts or power is restored.

I am running this on the simulator using a second ADC input in place of the Encoder (wish they would add one), and 2 LEDs to indicate the CW or CCW direction is being used.
I am new to PIC programming and PICs in general, so I am not sure how much overhead (time) reading an encoder uses
I will show my ignorance by the fact that the spec sheet <P16F1827> shows pin6(RB0) as the interrupt but it is already in use by the LCD. Not sure if I could place the "STOP" switch on this pin as well, and use an interrupt for this as opposed to just looking for the input of the switch.

Now that we are all confused, any suggestions?

Bob

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Suggestion for program flow

Post by Sean »

Do you know the maximum frequency of the encoder pulses?

It might be possible to use a timer interrupt to force regular polling of the I/O, allowing the encoder signals to be connected to any available inputs.

Post Reply