CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interrupt on external edge L to H

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
BIGANDBAD
Guest







Interrupt on external edge L to H
PostPosted: Thu Jan 29, 2009 1:16 pm     Reply with quote

I am just getting back into pic programming after 3 years of not programming. I am using a 16F877a and i want to use any pin to increment a value on every low to high transition
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 1:29 pm     Reply with quote

This sounds like a homework assignment. If you had a real project
you would tell us what the overall purpose is, and then maybe we would
come up with a better solution.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 1:30 pm     Reply with quote

ext_int_edge function allows to fire an interrupt routine when a falling/rising edge occurs on the PIC EXT_INT input.
search the forum for ext_int_edge examples.
BIGANDBAD
Guest







Interrupt on external edge L to H
PostPosted: Thu Jan 29, 2009 2:05 pm     Reply with quote

It is not a homework assignment. I am trying to use a pulse and direction signal that will drive a stepper motor, originally an open loop system into a closed loop system. Step and direction will tell the chip to move the 1/16 micro stepped motor to move .001" with a feedback signal from a magnetic hall effect linear encoder.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Interrupt on external edge L to H
PostPosted: Thu Jan 29, 2009 3:43 pm     Reply with quote

BIGANDBAD wrote:
It is not a homework assignment. I am trying to use a pulse and direction signal that will drive a stepper motor, originally an open loop system into a closed loop system. Step and direction will tell the chip to move the 1/16 micro stepped motor to move .001" with a feedback signal from a magnetic hall effect linear encoder.

I don't see what this has to do with interrupting on an external edge or incrementing a value. Is your PIC playing the role of receiving step and direction pulses, and are those step pulse what is causing the interrupt on L to H? Or is your PIC generating step and direction pulses to a stepper translator module, in which case maybe the linear encoder pulses are what is interrupting your PIC? In either case, you wouldn't be simply incrementing a value. You would be incrementing or decrementing it, depending on whether the stepper motor is moving one way or the other.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
BIGANDBAD
Guest







PostPosted: Fri Jan 30, 2009 3:50 am     Reply with quote

OK the original setup was a step and direction signal going to the motor drive board, open loop no feedback. the pic is now getting the step and direction signal and outputing its own step and direction signal to the motor drive board based on feedback from a quadrature encoder (linear). It will use a ds30f2010, i don't have it to play with yet so i am using a 16f877a to play with and would like to get the external interrupts to work. also is there an easy way to make a counter? I use PLC's everyday and am trying to learn pic's again.
Thanks
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Fri Jan 30, 2009 7:19 am     Reply with quote

BIGANDBAD wrote:
...the pic is now getting the step and direction signal....based on feedback from a quadrature encoder (linear). It will use a ds30f2010, i don't have it to play with yet so i am using a 16f877a to play with and would like to get the external interrupts to work. also is there an easy way to make a counter?....

You have two input problems. One is reading the external step pulses. That you can do by using the external interrupt pin. In response to each external interrupt, poll the direction signal and based on that signal, either increment or decrement an internal variable that represents the desired position.

The other input problem is the quadrature encoder. You will have an easy time of it with the ds30f2010, because it has a hardware quadrature encoder input that will maintain an up/down counter for you without any software intervention. But the 16f877a is not so wonderfully equipped. You will need either some external circuitry to read the quadrature encoder, or else some fairly fast polling of two inputs to manage a state machine to develop the internal up/down counter. It is a shame to waste so much development effort on a temporary PIC when a much better PIC will be used in your eventual design.

Finally, you will have to tie these two input processes together into a closed-loop controller. While everything else is going on, you will have to periodically compare the internal desired position (based on the step and direction inputs) with the actual position (based on the quadrature encoder input). Based on this comparison, you will have to decide to issue step and direction output pulses and at what speed in order to make the two positions equal.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
BIGANDBAD
Guest







PostPosted: Fri Jan 30, 2009 12:27 pm     Reply with quote

Thanks for the responce.
Is it possible to increment the counter on an incoming pulse and direction signal, and at the same time measure the frequency on that same pin of the incoming signal? Or do i have to route the same signal to another pin?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Fri Jan 30, 2009 4:05 pm     Reply with quote

BIGANDBAD wrote:
Thanks for the responce.
Is it possible to increment the counter on an incoming pulse and direction signal, and at the same time measure the frequency on that same pin of the incoming signal? Or do i have to route the same signal to another pin?

You can do it all on one pin. But I don't understand why you would want to measure the frequency. Is this for the step pulse? Then all you need to do is count them, not measure their frequency. Also you keep saying "increment" when you should be saying "increment or decrement". If the direction signal is one way, then you increment. If it is the other way, then you must decrement.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
BIGANDBAD
Guest







PostPosted: Fri Jan 30, 2009 6:46 pm     Reply with quote

YES incoming pulses need to be incremented and decremented to tell the motor what position it needs to go to. Also the frequency of the pulses need to be known to tell the motor at what velocity it needs to spin. All of this will probably end up in a PID loop. Is it possible to calculate frequency from the quadrature encoder hardware QEI?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Fri Jan 30, 2009 6:51 pm     Reply with quote

BIGANDBAD wrote:
...All of this will probably end up in a PID loop. Is it possible to calculate frequency from the quadrature encoder hardware QEI?

The frequency of the step pulses you produce will be determined by your PID calculations, based on the difference between the desired postion (maintained by the incoming step, direction) and the actual postion (maintained by the quadrature encoder). The frequency of the input step pulses is irrelevant to this calculation.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
BIGANDBAD
Guest







PostPosted: Fri Jan 30, 2009 10:11 pm     Reply with quote

OK THANKS
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group