完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好!我使用PIC18f4550/PIC18f4431作为通过SSI/SPI协议的绝对编码器接口,分别借助于差分线驱动器/接收器IC(AM26LS31x和AM26LS32Ax)。编码器模型;BEI M40系列,绝对,64圈,灰色编码,串行RS422协议。现在的问题是:当位置改变(编码器旋转)时,串行移位寄存器输出到MCU端的缓冲寄存器(SSPBUF)的随机值跳到附近。但是,当编码器是静止的(没有旋转)、位置值ok和一致的.xc8代码SPI读取功能块:无符号字符._ReadSPI(void){无符号字符TemVar1、TemVar2、TemVar3;无符号字符第一字节[3]、编码器[3];LATAbits.LA5=0;//enable read slavePIR1bits.SSPIF=。0;//清除中断标志//SSPSTATBITS.BF=0;SSPBUF=0x00;/ /启动总线循环;(!)PIR1bits.SSPIF);//等待直到周期完成//Delay1KTCYx(10);TemVar1=SSPBUF;PIR1bits.SSPIF=0;SSPBUF=0x00;//启动总线周期(!PIR1bits.SSPIF);//等待直到周期完成//Delay1KTCYx(10);TemVar2=SSPBUF;//Delay1KTCYx(10);PIR1bits.SSPIF=0;SSPBUF=0x00;//启动总线周期(!PIR1bits.SSPIF);//等待直到循环完成//Delay1KTCYx(10);TemVar3=SSPBUF;//Delay1KTCYx(10);LATAbits.LATA5=1;//enable read slave//在数据循环读取.my_putsUSART(“ABSOLUTE ENCODER=”)、sprintf(firstbyte,“%u”,TemVar2);//type转换//my_putsUSART(“2stByteTest=”);putsUSART(第一字节);//1sy字节到PCmy_putsUSART(“”);sprintf(编码器,“%u”,TemVar3);//type转换为无符号chARMy_putsUSART(编码器);//2字节到PC.(0);//return with byte read}朋友请提供一些输入来修复它。非常感谢您的期待。
以上来自于百度翻译 以下为原文 Hi everybody! I am using PIC18f4550/PIC18f4431 for absolute encoder interface through SSI/SPI protocol with the help of differential line driver/receiver ICs respectively (AM26LS31x andAM26LS32Ax). Encoder model; BEI M40 series, absolute, 64 turn,grey coded, serial RS422 protocol. Now the problem is: The serial shift register output into buffer register at MCU end (SSPBUF) jumps to near by random value when position changes (encoder rotates). but there is no any jumps when encoder is stationary (no rotation), position value ok and consistent. xc8 code SPI read function block: unsigned char My_ReadSPI( void ) { unsigned char TemVar1, TemVar2, TemVar3; unsigned char firstbyte[3], encoder[3]; LATAbits.LA5 = 0; //enable read slave PIR1bits.SSPIF = 0; // Clear interrupt flag //SSPSTATbits.BF = 0; SSPBUF = 0x00; // initiate bus cycle while(!PIR1bits.SSPIF); // wait until cycle complete // Delay1KTCYx(10); TemVar1 = SSPBUF; PIR1bits.SSPIF = 0; SSPBUF = 0x00; //initiate bus cycle while(!PIR1bits.SSPIF); // wait until cycle complete //Delay1KTCYx(10); TemVar2 = SSPBUF; //Delay1KTCYx(10); PIR1bits.SSPIF = 0; SSPBUF = 0x00; //initiate bus cycle while(!PIR1bits.SSPIF); // wait until cycle complete //Delay1KTCYx(10); TemVar3 = SSPBUF; //Delay1KTCYx(10); LATAbits.LATA5 = 1; //enable read slave //after the data cycle read disable my_putsUSART("ABSOLUTE ENCODER = "); sprintf(firstbyte, "%u", TemVar2); //type conversion //my_putsUSART("2st Byte Test = "); my_putsUSART(firstbyte); //1sy byte to PC my_putsUSART(" "); sprintf(encoder, "%u", TemVar3); //type conversion to unsigned char my_putsUSART(encoder); //2nd byte to PC return (0); // return with byte read } Friends please give some inputs to fix it. thank you very much in anticipation. Sjorphail |
|
相关推荐
7个回答
|
|
嗨,请阅读有关“格雷码”的信息,格雷码计数器是这样计数的(例如,4位):位置计数器0:00001:00012:00113:00104:01105:01116:01017:01008:11009:110110:111111::你的计数器代码:0;1;3;2;6;7;5;4;12;13;15;14;14;y;^;
以上来自于百度翻译 以下为原文 Hi, please read informations about "Gray Code" A Gray Code counter is counting like this: (Example for 4 bits) Position Counter 0: 0000 1: 0001 2: 0011 3: 0010 4: 0110 5: 0111 6: 0101 7: 0100 8: 1100 9: 1101 10: 1111 11: 1110 12: 1010 13: 1011 14: 1001 15: 1000 If you simply take this bits without converting it into binary code your counter counts: 0;1;3;2;6;7;5;4;12;13;15;14;10;11;9;8 |
|
|
|
编辑:请原谅我,我只是注意到你正在使用一个8位的PIC。下面的代码是16位设备。我是舒尔,你会发现在C中的转换例子在互联网上。没有任何保证:一个可能的转换之间的16位灰色和二进制的汇编:附上一个主。来调用和测试函数。
以上来自于百度翻译 以下为原文 Edited: Please forgive me, I just noticed you are using an 8-Bit PIC. The code below is for 16 bits devices only. I'm shure you will find conversion examples in C in the internet. without any guarantee: one of several possibilities to convert between 16bit gray and binary in assembly: #include .global _BinaryToGray .global _GrayToBinary .text _BinaryToGray: ; input: W0, binary-code ; output: W0, gray-code LSR W0,#1,W1 XOR W0,W1,W0 RETURN _GrayToBinary: ; input: W0, gray-code ; output W0, binary-code ; registers used: ;W4: bit counter ;W3: copy of gray-code ;W2: sampling of binary-code ;W1: mask MOV #0x8000,W1 ;initial mask, shifted later MOV W0,W3 ;save gray-code AND W3,W1,W2 ;init temporary result: gray MSB= binary MSB ; do the rest 15 bits MOV #15,W4 CONTINUE: LSR W1,W1 ;shift mask LSR W2,W0 ;temporary result shifted one bit right XOR W0,W3,W0 ;XOR result with gray-code AND W1,W0,W0 ;use only one bit (mask) IOR W0,W2,W2 ;add bit to result DEC W4,W4 ;next bit BRA NZ,CONTINUE MOV W2,W0 ;result to W0 RETURN _GrayToBinary2: ; input: W0, gray-code ; output W0, binary-code ; registes used: ; W1: bit counter ;replace gray-code by binary-code bit by bit in W0 MOV #15,W1 ;MSB needs no conversion, convert 15 bits LOOP1: RLNC W0,W0 ;rotate BTSC W0,#0 ;check result of last conversion BTG W0,#15 ;toggle next bit if previous result was 1 NO_TOGGLE: DEC W1,W1 BRA NZ,LOOP1 RLNC W0,W0 ;16th rotation RETURN Attached a main.c how to call and test the functions. Attachment(s) main.c (0.57 KB) - downloaded 128 times |
|
|
|
与BEI编码器的SSI接口不容易完全理解。编码器使用RS422差分线驱动器和接收器作为物理接口。逻辑协议是同步CLOCK/DATA,而不是在许多使用RS422差分信令的设备中发现的异步串行数据。本文件(http://www.bei..com/pdfs/ssi_parity.pdf)描述了当前BEI传感器使用的SSI CLOCK/DATA协议。在查看BEI网站(http://www.bei..com/)之后,没有看到列出的M40系列编码器。如果原始海报可以为传感器提供零件编号,则可以得到一些更好的信息。来自post#1的代码看起来像是从SPI接口读取24位。这不符合SSIPARITI.PDF文档中描述的协议。这样做可能会使传感器中的SSI引擎处于无效状态。
以上来自于百度翻译 以下为原文 The SSI interface to BEI encoders it not easy to fully understand. The encoders use RS422 differential line drivers and receivers for the physical interface. The logical protocol is a synchronous CLOCK/DATA, not the asynchronous serial data found in many devices using RS422 differential signaling. This document ( http://www.beisensors.com/pdfs/ssi_parity.pdf ) describes the SSI CLOCK/DATA protocol used by current BEI sensors. After looking on the BEI web site ( http://www.beisensors.com/ ) is did not see the M40 series of encoders listed. If the Original Poster can provide a part number for the sensor it may be possible to get some better information. The code from post #1 looks like it reads 24-bits from the SPI interface. This does not meet the protocol described in the ssi_parity.pdf document. Doing this may leave the SSI engine in the sensor in an invalid state. |
|
|
|
嗨,伙计们,我非常感谢你们的努力和关心来解决这个问题。非常感谢大家,你们的每一个反馈都是非常有帮助和鼓舞人心的。看来我使用的旧BEI编码器绝对是“mt40d-x-hss1024n-64t-gd10-cr-e-c14-t-5”。没有找到关于同一编码器的任何信息,我已经写信给BEI 2或3次,但根本没有回应。再次感谢。
以上来自于百度翻译 以下为原文 Hi Guys, I really appreciate your effort and concern to fix the problem. I thank you all very much, yours each feedback is really helpful and encouraging. It looks that the old BEI encoder i used is absolute "mt40d-x-hss1024n-64t-gd10-cr-e-c14-t-5". Am not finding any information about the same encoder, I have written to BEI 2 or 3 times but no response at all. thanks again. |
|
|
|
这是我所能找到的:MT40数据表:(http://www.bei..c...te-Encoder-MM-086B.pdf)SSI指南和插针:(http://www.bei..com/pdfs/ssi%20interface.pdf)SSI实现应用说明:(https://www.posital.com/media/posital_media/./AbsoluteEncoders_Context_Technol)ogy_SSI_AppNote.pdf)SSI Wikipedia文章:(https://en.wikipedia.org/wiki/Syn._Serial_Interface)匹配连接器:ITT Cannon:MS3116F14-19SSouriau连接技术:MS3116F1419SWDatasheet:(http://www.souriau.com/fi...duct_pdf/P016-P041.pdf)
以上来自于百度翻译 以下为原文 This is what I could find: MT40 Datasheet: ( http://www.beiprecision.c...te-Encoder-MM-086B.pdf ) SSI guide with pin out: ( http://www.beisensors.com/pdfs/ssi%20interface.pdf ) SSI implementation application note: ( https://www.posital.com/media/posital_media/documents/AbsoluteEncoders_Context_Technology_SSI_AppNote.pdf ) SSI Wikipedia article: ( https://en.wikipedia.org/wiki/Synchronous_Serial_Interface ) Mating connector: ITT Cannon: MS3116F14-19S Souriau Connection Technology: MS3116F1419SW Datasheet: ( http://www.souriau.com/fi...duct_pdf/P016-P041.pdf ) |
|
|
|
非常好的工作来获得所有这些数据表和应用程序-笔记!mt40d-x-hss1024n-64t-gd10"-cr-e-c14-t-5-从数据表上看,输出似乎是二进制编码的,而不是灰色编码。-总分辨率是16位:单圈10位(0...1023)和圈数6位(0...63)-串行接口上的总位数是16位?-设备是否有奇偶校验位?(串行输出另2位?)-在任何情况下,对于起始位,需要附加的时钟脉冲。那么需要17个时钟还是19个时钟?非常奇怪的装置。
以上来自于百度翻译 以下为原文 Very good work to get all these datasheets and App.-notes ! mt40d-x-hss1024n-64t-gd10"-cr-e-c14-t-5 - From the datasheet it seems the output is binary coded and NOT Gray-Code. - The total resolution is 16 bits: 10 bits for single turn (0...1023) and 6 bits for counting the turns (0...63) - The total number of bits on the serial interface is 16? - The device has parity bit or not ? (another 2 bits at the serial output?) - In any case, for the Start bit an additional clock-pulse is required. So 17 clocks required or 19? Very strange device. |
|
|
|
我理解Wikipedia页面上描述的SSI协议的方法是,当CLOCK流已经高了至少40微秒时,第一个高到低转换将编码器状态锁存到多位移位寄存器中,其中第一个位移位总是高而最后一个位shi。FTED总是很低。之间的比特数取决于编码器配置。当CLOCK流在60KHz(16us)或更快时,锁存的数据循环到输出流。我看不到一种子弹证明的方法来检测这种比特流中“真实数据”比特的数量。知道编码器的数据位的数量可能是必需的。一个可能的实现方式是设置40us的CLOK输出HIGH,然后使用SPI功能块读取16个数据位的足够八位字节加上第一个高位和最后一个低位的2个比特。如果有人想给我发送这些旋转编码器之一,我可以计算出来。如果你愿意的话,给我发个私人信息。
以上来自于百度翻译 以下为原文 The way I understand the SSI protocol described on the Wikipedia page is that when the CLOCK stream has been HIGH for at least 40 microseconds the first HIGH to LOW transition latches the encoder state in a multi-bit shift register where the first bit shifted out is always HIGH and the last bit shifted out is always LOW. The number of bits in between depends on the encoder configuration. When the CLOCK stream is at 60KHz (16us) or faster the latched data recirculates to the output stream. I do not see a bullet proof way to detect the number of "real data" bits in this kind of bit stream. Knowing the number of data bits for the encoder may be required. A possible implementation could be to set the CLOCK output HIGH for 40us, then use the SPI function block to read enough octets for 16 data bits plus 2 bits for the first HIGH and last LOW bits. If someone wants to send me one of these rotary encoder I could work it out. Send me a Private Message if you are up for it. |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
727浏览 1评论
612浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
501浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
626浏览 0评论
524浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 08:18 , Processed in 1.317076 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号