Edge detection circuit to external interrupt w/ DSpic

Status
Not open for further replies.

variaseng

New Member
Hi, I'm trying to monitor 5 encoders at the same time using DSPIC30f4011. I want to be able to use external interrupts so my count resolution will be good. But I have only a limited number of pins (since I need the other pins for other stuff), and limited number of external interrupts. So I want to use an edge detection circuit for this implementation. But I don't know where to begin. The thing I wanna do is, when the edge detection circuit detects an edge from the five encoders, the microcontroller can process which encoder was activated and serve it at the one external interrupt I have available in the dspic. The encoders can also simultaneously activate. I think I need other hardware to complete this, but I'm having a difficulty finding what. Thank you very much for your help!
 
The chip has a module that acts similar to the 18F interrupt on change.
Look at section 8.3 Input Change Notification Module in the processor datasheet.
Generally I would say that if you are out of pins use a chip with more pins.

If you really can't go to a bigger chip you might look at a port expander
MCP23017/MCP23S1


There is a register to ell which bit caused the interrupt. A nice feature allows the interrupt to happen if the register pin(s) differ from the last value.

Good luck
 
Thank you very much for your reply. I've looked at the datasheet of MCP23017 and am currently reading it. It does seem to fit my need. I can use it as an interrupt interface and I can service my 5 encoders simultaneously. For hardware addressing, it seems I don't need this, I just need to put the encoders in GPIO pins. Anyway, I was searching on how to program/set the registers in MCP23017. I'm totally confused in what I've seen so far. One suggestion I saw is to connect the MCP23017 through the I2C interface of a microcontroller and to set the registers through this (though I am not quite sure how this is done). What programmer should I use in order to program the MCP23017. Is it not possible to program the MCP23017 w/o connecting its I2C/SPI to a microcontroller?

Again, thanks very much for your replies and help!
 
Last edited:
To use the MCP23017 you are going to have to learn to use I2C if you don't already. There is an SPI version but that will take 2 more pins unless you already have SPI in your design then it would only require the CS signal as the others can be shared.

This device acts as an extension to the existing processor.

You do not use a programmer to program the MCP23017. Your program in your dsPIC sends reads and writes over the I2C interface to do that.

Look at
TABLE 1-2: REGISTER ADDRESSES
Use the I2C to read and write to the registers name show in the "Access to" column at the addresses specified.

https://ww1.microchip.com/downloads/en/DeviceDoc/51456b.pdf

See 3.17.3 Example of Use in above
for an idea how I2C is used to read and write to another device.

I must admit there is a lot to learn here. If you do not know I2C there may be too much to make this a reasonable solution for you.
 
Thank you very much for your replies! So I need to learn i2c first. I will be using mikroC PRO for dspic environment and there is a library for i2c interface there so maybe i'll try work that out. But in using MCP23017, i have to constantly send the results whenever the encoder is active through i2c interface. Should I be worried about the delay this would cause?
 
Does this mean that for every one bit sent to the microcontroller, it takes 0.588us? So to write/read a whole 8-bit register it would take 4.7us or 212.5kHz?
 
Okay, thank you very much for your replies! Using this IC would seem to be my top choice. But a friend suggested to me to do it like this. Feed every Encoder A signal of the 5 encoders through a falling edge detector each then OR the outputs, and connect this as an external interrupt in the dspic30f4011. These Encoder A signals and B signals are also connected to GPIO pins of the dspic. Then when the external interrupt is asserted, the dspic will check the GPIO pins where I input the Encoder A signals and check to see which is asserted. Then when I got the GPIO asserted pin, I will check the corresponding Encoder B signal GPIO pin to see how if I should increment/decrement. What's got me confused right now is, would this be fast enough to do the counting accurately? Even when the encoders are moving simultaneously? For example, is the latency time from seeing the external interrupt in the dspic to checking the Encoder B in the GPIO pin short enough such that it would seem like you looked at the encoder outputs at the same time?
 
I do not see how your friends idea will catch all changes of A and B.

I was thinking you could do this with just the dsPIC30F4012. But it only has 8 pins that will generate an interrupt on change. The dsPIC30F4011 (40 pin) has 10 which is enough to run every encoder line into a interrupt on change pin.

This is what I wrote prior to knowing that.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…