View previous topic :: View next topic |
Author |
Message |
bulut_01
Joined: 24 Feb 2024 Posts: 219
|
|
Posted: Fri Mar 14, 2025 9:32 am |
|
|
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
|
|
Posted: Fri Mar 14, 2025 10:24 am |
|
|
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
|
|
Posted: Fri Mar 14, 2025 10:28 am |
|
|
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
|
|
Posted: Sat Mar 15, 2025 5:37 am |
|
|
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
|
|
Posted: Sun Mar 16, 2025 4:27 am |
|
|
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
|
|
Posted: Sun Mar 16, 2025 4:51 am |
|
|
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
|
|
Posted: Sun Mar 16, 2025 5:38 am |
|
|
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
|
|
Posted: Sun Mar 16, 2025 7:35 am |
|
|
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
|
|
Posted: Mon Mar 17, 2025 1:40 am |
|
|
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
|
|
Posted: Mon Mar 17, 2025 12:34 pm |
|
|
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
|
|
Posted: Fri Mar 21, 2025 5:15 pm |
|
|
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);
}
|
|
|
 |
|