Microchip
直播中

李欣

7年用户 267经验值
私信 关注
[问答]

捕获结果不符合预期

嘿,我有我的捕获代码。我相信我的捕获是正确的,但我想是我决定结果和输出我有一个问题。我正试图监测一个轴的速度(目前连接在一个演习的测试)我的捕获有溢出,因为速度太慢,以获得捕获没有time1翼(见附件),所以当我捕获数据并把溢出数增加到一个24位数字的低速时,当我期望数字接近恒定速度时,我得到了一个巨大的范围。请帮助我,因为我已经在这个问题上停留了很长时间了。杰森?

以上来自于百度翻译


      以下为原文

    Hey all,

I'm having an isue with my capture code.  I believe my capture is working correctly but I think its the was I determine the results and output I'm having an issue with.

I'm trying to monitor a speed of a shaft (Currently connected on a Drill for test)

My Capture has an overflow as the speed is too slow to get a capture without timer1 overflowing.

(See attachment)

So when I'm capturing the data and putting the overflow number to increase the timervalue to a 24bit Number At low speeds I get a massive range when I expect the number to be closer bue to the constant speed.

Please help as I've been stuck on this for ages??

jason
   Attached Image(s)

回帖(6)

高峰

2019-3-4 15:46:27
另外,我认为这是与MSB和LSB有关的……但无法解决吗?

以上来自于百度翻译


      以下为原文

    Additional;
 
I think it's to do with MSB & LSB... but unable to work it out?
举报

杨叶

2019-3-4 16:05:45
嗨,你觉得论坛上的人能猜出你用的是哪一张照片吗?1200个?如果你需要一些帮助,请给出细节:PIC?编译器?你的程序?当做

以上来自于百度翻译


      以下为原文

    Hi,
Do you think people on this forum can guess which PIC you're using ...out of 1200 ?
If you want some help give details : PIC?, compiler?, your program?
Regards
 
举报

高峰

2019-3-4 16:14:23
RISC,对不起,我的问题更多的是关于数据和数据解释。但是,在这里……PIC18F4680C18MPLAB IDV863i AM设置ECP1作为捕获,在我的中断期间,在我的CAN TxMy可以监视正在读取;can MexGe 0x4fByb顺序:Moto LoalStand(BIT):16STARTBIT:8.我希望这能帮助你回答我关于MSB和LSB的问题吗?我的抓捕工作很好,但似乎并不稳定(我想)杰森

以上来自于百度翻译


      以下为原文

   


RISC, 
 
Sorry, my question was more about the data and the data interpretation. 
 
but, here you go...
 
PIC18F4680
C18
MPLAB IDE v8.63
 
I am setting up the ECCP1 as a capture,
 
During my interrupt
 // Overflow on Tmr1
 if (PIR1bits.TMR1IF)
  {
  Tmr1OrFlw++;
  PIR1bits.TMR1IF = 0;
  }

 // Capture on pin RD4
 if (PIR2bits.ECCP1IF)
  {
  TMR1H = 0x00;
  TMR1L = 0X00;

  Tmr1OrFlwResult = Tmr1OrFlw;
  Tmr1OrFlw = 0x00;

  PIR2bits.ECCP1IF = 0; // clear in sw
  PIR2 = 0x00; // Above line doesn't seem to work on it own?
  }
 }
 
Then  during my CAN Tx
 
if (tTimer_MPH_Data >= Timer_25mS)
   {
   tTimer_MPH_Data=0;
       iTXAttempts= 1; // Try to send once before calling it a day
       ID = 0x4F;
 
   // Clear down the CAN buffers-------------//
   data[0] = Tmr1OrFlwResult;
   data[1] = ECCPR1H;
   data[2] = ECCPR1L;
   data[3] = Tmr1OrFlw;
 
       while ((!ECANSendMessage(ID,data,4,ECAN_TX_STD_FRAME))&& iTXAttempts!=0) // If failed...
           iTXAttempts--;

   }
 
My CAN monitoring is reading the;
CAN Messgae 0x4F
Byte Order : Motorola
Length (bit) : 16
Startbit : 8
 
I hope this helps you answer my question about is the MSB and LSB in the correct order?  My Capture is working fine but just doesn't seem to be stable (I think)
 
Jason
举报

杨叶

2019-3-4 16:25:30
嗨,你为什么使用这些旧的软件工具(C18和MPLAB)?两者都是至少6岁……已经被XC8和MPLAB X取代。对于捕获,最重要的是确保一些捕获没有丢失或溢出……那么,你最小的捕获量是多少?你确信你有足够的时间处理它直到下一个到来吗?你有没有其他的中断比你所展示的?你声明你的中断变量是不稳定的吗?你有没有想过如果捕获中断发生在下面的2行之间会发生什么?你的中断总是在主程序中同时启用还是有时会使其中之一中断?如果你将其中之一禁用,则必须将中断标志测试更改为:

以上来自于百度翻译


      以下为原文

    Hi,
Why do you use such old software tools (C18 & MPLAB).
Both are at least 6 years old...and have been replaced by XC8 and MPLAB X.
 
Regarding capture, the most important is to make sure that some capture is not missed or overflowing...
So what is your smallest capture ? Are you sure you have enough time to process it until the next one comes ?
Do you have other interrupts than the ones you have shown ?
 
Did you declare your interrupt variables as volatile ?
 
Have you thought about what would happen if the capture interrupt happens in between 2 lines below...

   data[1] = ECCPR1H;
//what happen if capture interrupt takes place here...
   data[2] = ECCPR1L;


 
Are your interrupt always enabled simultaneously in you main program or do you sometimes diable one of them ?
If you diable one of them then you must change your interrupt flag tests to this :

 if (PIE1bits.TMR1IE && PIR1bits.TMR1IF)

...
 if (PIE2bits.EECP1IE && PIR2bits.ECCP1IF)
....


Regards
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分