ycnr
Newbie level 5
- Joined
- Feb 9, 2015
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 98
I use 18F8722 in a project. This device has two hardware SPIs and I have run to read two encoders. I need one more SPI channel. May i use Hardware and sofware SPIs together. I tried but i couldn't succeed. What are your opinions and advices? Thanks in advance.
I should read two encoders at same time and they should move to forward or backward synchronously.
I should read two encoders at same time and they should move to forward or backward synchronously.
How can two software SPI work at the same time? And maybe a third one..
I know, (especially with the use of assembly), it could be possible, but is it
really an improvement over a fast hardware solution?
I would be curious of an implementation that reads 2 devices at the same time
using assembly. Basically assembly or C does not change anything. There is
absolutely nothing that you can do in assembly and that you can't in C,
except maybe accessing a specific processor register (although there might
be C tricks I don't know).
Can you supply a datasheet for these encoders?
What type of encoders are they?
What is the resolution or granularity of the encoders?
What SPI clock rates do the encoders support? And what is the current SPI clock rate?
What exactly are the encoders measuring?
What is the effective RPM range of rotational/angular movement?
The phrase "at the same time" is relative, in relation to reading a mechanical device, like an encoder, the time interval between reading the value of one encoder followed immediate by reading the value of the other encoder is typically insignificant, in the tens of microseconds range for higher SPI clock rates. Typically, changes of state at the mechanical side occur a considerable slower rates than that of the time interval between sequential reads of two encoders.
BigDog
Hi,
Additional y to BigDog's post....
How can two software SPI work at the same time? And maybe a third one..
I know, (especially with the use of assembly), it could be possible, but is it really an improvement over a fast hardware solution?
Klaus
As Klaus suggested, there is inherent latency when utilizing two hardware SPI modules, each module must be sequential triggered to perform the read task, therefore even with the application of two hardware SPI modules, the encoder values are not retrieved simultaneously.
Another option, likely more prudent and practical, is to attach the third encoder to one of the existing hardware SPI modules. First the values of the two primary encoders are retrieve, then the value of the third encoder is retrieved, upon which the cycle begins again. Implementing this method, provides a more deterministic approach, not relying on the processor to implement and perform the SPI communications protocol and thereby freeing it up to execute calculations on the retrieved values, off loading the SPI communications to the hardware SPI modules.
Certainly, implementation of a soft SPI is possible, however in terms practicality, feasibility and functionality in comparison to the above outlined method, doubtful.
BigDog
Hello!
I would be curious of an implementation that reads 2 devices at the same time
using assembly. Basically assembly or C does not change anything. There is
absolutely nothing that you can do in assembly and that you can't in C,
except maybe accessing a specific processor register (although there might
be C tricks I don't know).
The only solution to use 2 SPIs at the same time (i.e. clocks and data are
synchronized) would be a hardware implementation. Maybe it would be possible
on some processors with large instructions (I'm thinking about one processor
I used in the past, called "equator" with VLIW, which stands for very large
instruction word). One instruction word was divided in more instructions.
In such an implementation, you could imagine that you have 2 synchronous
move instructions that both set one byte in each SPI engine.
Otherwise, using 2 SPIs at the same time in small processors is simply not
possible, assembly or not.
As BigDog said, it really depends on what you call "read 2 encoders at the same
time". Here is a blind calculation (blind because I don't know what you want to do).
Suppose your SPI can run at 10 MHz clock (which is the case of many encoders I know).
If you read a 40 bit data frame (which is also a common case), then you will need
4 µs. Reading 2 encoders will therefore give you values that are 4 µs apart.
Now let's suppose that you are reading an encoder spinning at 6000 rpm, which
is a very common speed for motors. What would be the angular error?
6000 rpm is 100 turns per second, which is 36000 degrees per second.
Therefore, within 4 µs, your motor moves by 36000 x 4 / 1000000 = 0.144 degree.
This is quite acceptable in many cases.
Dora.
Hi,
Code:I would be curious of an implementation that reads 2 devices at the same time using assembly. Basically assembly or C does not change anything. There is absolutely nothing that you can do in assembly and that you can't in C, except maybe accessing a specific processor register (although there might be C tricks I don't know).
I thought of two SPI interfaces at the same port. Then instead of a bit manipulation you could use a byte write for two spi_clock generation and two spi_mosi generation at the same time, also you could do the read of two spi_miso at the same time. After that a lot of bit manipulations are needed to bring the read in data in a useful format. This part of code i'd write in assembler.
Although possible, I'd not recommend such programming.
Klaus
Yes. This is the way to go.I undertand from your what you said that I can connect two linear encoders to one SPI module and read by selecting SS pins. Therefore other SPI can use to read Rotary Encoder.
Have i understood correctly?
Resolution = 5μm
6 outputs but i use A, B channels and Z reference
Traverse speed (max) = 2m/s
Travel Length = 25 cm
Other one is Incremental Rotary encoder.
Maximum rpm = 6.000 [rpm]
Max. output frequency = 200 [kHz]
Housing Diameter = ø58 [mm]
Hollow shaft = ø10 [mm]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?