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

encoder pulse measurement
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bulut_01



Joined: 24 Feb 2024
Posts: 219

View user's profile Send private message

PostPosted: Fri Mar 14, 2025 9:32 am     Reply with quote

temtronic wrote:
OK, did a quik read of the datasheet...

this 'should' work

setup timer1 register pair to 0xfffe and enable it's interrupt.

when it overflows ( 1 pulse from encoder....)
have the timer1 ISR

read the 'direction' bit from the 4013 chip.
then either add or subtract 1 from 'thecount'
lastly preload the timer 1 register pair with 0xfffe
exit the ISR


mr. temtronic thank you Can you give an example of what you said by writing code?
at least this sounds good in my brain.....
gaugeguy



Joined: 05 Apr 2011
Posts: 325

View user's profile Send private message

PostPosted: Fri Mar 14, 2025 10:24 am     Reply with quote

Instead of connecting your encoder to the T13CKI pin can you connect it to an interrupt pin? This would make it easier. What pin does your encoder direction signal go to?
bulut_01



Joined: 24 Feb 2024
Posts: 219

View user's profile Send private message

PostPosted: Fri Mar 14, 2025 10:28 am     Reply with quote

gaugeguy wrote:
Instead of connecting your encoder to the T13CKI pin can you connect it to an interrupt pin? This would make it easier. What pin does your encoder direction signal go to?


mcu all pins are full. unfortunately there are not many options other than t13ckl.
temtronic



Joined: 01 Jul 2010
Posts: 9445
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 15, 2025 5:37 am     Reply with quote

have a good look at the examples CCS supplies in the 'examples' folder. You should be able to see how to setup the timer and create the ISR.
Post your code, then we can help better.
Ttelmah



Joined: 11 Mar 2010
Posts: 19765

View user's profile Send private message

PostPosted: Sun Mar 16, 2025 4:27 am     Reply with quote

It really would be hugely easier if you could use a pin that has an interrupt.
There are seven on the chip, so (for example), if your direction signal is
going to one that does support this, then simply swap these two wires,
and things get a lot easier.....
bulut_01



Joined: 24 Feb 2024
Posts: 219

View user's profile Send private message

PostPosted: Sun Mar 16, 2025 4:51 am     Reply with quote

Ttelmah wrote:
It really would be hugely easier if you could use a pin that has an interrupt.
There are seven on the chip, so (for example), if your direction signal is
going to one that does support this, then simply swap these two wires,
and things get a lot easier.....


When remote control data arrives for a certain period of time, ext_int is used, encoder pulse miss may occur. The reason for using hardware external count is that the system should not miss an encoder pulse under any circumstances.
temtronic



Joined: 01 Jul 2010
Posts: 9445
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 16, 2025 5:38 am     Reply with quote

hopefully your 'remote control data' is being stored in a buffer through an ISR ??

have you tried my idea yet ? less than 20 lines of code.
bulut_01



Joined: 24 Feb 2024
Posts: 219

View user's profile Send private message

PostPosted: Sun Mar 16, 2025 7:35 am     Reply with quote

temtronic wrote:
hopefully your 'remote control data' is being stored in a buffer through an ISR ??

have you tried my idea yet ? less than 20 lines of code.


We have talked about this before. The incoming data is decoding Manchester at the same time the 100 Hz signal comes from the motor encoder.
Ttelmah



Joined: 11 Mar 2010
Posts: 19765

View user's profile Send private message

PostPosted: Mon Mar 17, 2025 1:40 am     Reply with quote

Thing to understand here is that an interrupt edge detection, is latched
inside the PIC. So even if the event cannot be handled straight away, it
will not be 'missed'. You are only taking a signal at 10mSec intervals,
I've used encoders with thousands of lines per revolution, and still
coded to not miss even one pulse. Your encoder receiver could even use
the high priority interrupt, and if it's handling code is kept quick (just
incrementing /decrementing a counter), it can be handled in a very few
instruction times indeed.
temtronic



Joined: 01 Jul 2010
Posts: 9445
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 17, 2025 12:34 pm     Reply with quote

also if the ISR isn't fast enough, you can 'trim' the CCS supplied code if you're careful.

another option is to just poll the 'yes, have an interrupt' bit and take action. The interrupt itself does not have to be enabled.

which is 'best' depends on many factors of course.
bulut_01



Joined: 24 Feb 2024
Posts: 219

View user's profile Send private message

PostPosted: Fri Mar 21, 2025 5:15 pm     Reply with quote

I would like to thank the friends who helped me here for their interest and concern. The problem arose from a different part of the code. I am using the code below for the encoder, no pulse leakage was observed.

Code:
if(GET_TIMER1() > 0 && input(YON) == 0){
enkoder_pulse += GET_TIMER1();
set_timer1(0);
}
else if(GET_TIMER1() > 0 && input(YON) == 1){
enkoder_pulse -= GET_TIMER1();
set_timer1(0);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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