Hi Folks,
I Hope someone can help me here, first thing is that the code works fine it’s more a math prob.
Setup
CCS comp ver 4.071
18f4431 in MCHP ICD2 into the target board
4 mHz Osc
QEI MODULE IN x4 UPDATE MODE RESET ON MATCH 1:1 POSTSCALER(<PDC 1:0>=00)
VELR ON
TMR1 (div_by_8) SET TO INTERRUPT EVERY 10 mS (code below)
TMR5 (div_by_1)reset automatically after each capture.
Code:
//QUAD ENCODER SIMULATOR O/P ON A0 AND A1 TO QEA & QEB (A3 & A4)
//TURN A0 ON
//10mS
//TURN A1 ON
//10mS
//TURN A0 OFF
//10mS
//TURN A1 OFF ETC....
#INT_TIMER1 //set to interrupt every 10mS
tim()
{
if(flag==0)
{
output_toggle(pin_a0);
flag=1;
}
else
{
output_toggle(pin_a1);
flag=0;
}
set_timer1(64285);
}
I am using tmr1 as a QUADRATURE ENCODER simulator CHA o/p on A0 CHB o/p on A1 into the QEI module of same chip on the QEA and QEB pins respectively.
As I understand from the QEI and VELR section(f4431 datasheet) in this setting every edge of a QEA/B pulse pair generates a VELCAP pulse to TMR5, and when this happens you get the no of counts between pulse edge from TMR5, in the settings I have provided above this is 39 counts with respect to the interrupt time above.
I would like to convert this into an actual time measured in mS etc (it might seem simple at first but change the postscaler setting! Giving me a headache!!).
Reason why I am doing this is to check an encoder to see if the motor that is driving it through a gear box is slightly slowing or speeding up, I need to do this by measuring any change in time between the timing of QEA and QEB edge captures. Hope that explains it a bit. Hope someone can help
With kind regards and thanks
Dave
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
Posted: Sat Feb 12, 2011 4:25 pm
I think that the measurement should be about 10000 (microseconds) with the setup details provided, and no conversion would be necessary.
If that is true, then the task would be to find out why 39 is output instead of 10000.
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