You didn't specify how you plan to read pins: (1) by continuously polling, (2) by using interrupts and waiting for change of state.
In any ways, it is faster to group pins by 8 and make them contiguous, so they can be read all 8 pins at once. This way you will have 5 ports of 8 pins each. Reading such port gives uint8 result, where each bit corresponding to a pin state.
If using interrupts, enable such (grouped) pin interrupt for each port (total 5 interrupts are needed), and read pins state same way as polling inside the ISR handler.
You can find both techniques used in the ButtonSw32 custom component:
Thanks for the reply,
Which method to use read 40 pins status continuously polling, interrupts or waiting for change of state and how much time taking to read 40 pins. I am new in controller side Please provide links for code.
As suggested by BoTa_264741, there are different ways to achieve this., But it is better if you achieve this using interrupts as you won't waste CPU time by continuously polling. In the interrupt method, the you will check the Pin state only when there is a state change in the pins.
The easiest way is to assign 8 pins of the same port to a particular pin component. Please remember that one interrupt will be generated per port (ORed of all the individual pins of a port). We need to use the Pin_ClearInterrupt() API to clear the interrupt and this function will also return you which pin has triggered the interrupt and you can read the status of that port using the Pin_Read() API (Each bit will correspond to the on/off of that pin).
1. First drag and drop the pins components (digital input pin) to the Top Design:
2. In the Pins component window, disable HW connection. In the inputs tab, select interrupt type to both edges. (ie) This will generate an interrupt whenever the pin state changes from 1 to 0 or 0 to 1.
3. Do this for all the 5 components.
4. Drag and drop the ISR component and choose derived in the Interrupt Type
5. You need to write 5 ISRs for the 5 port interrupts.
6. In each of the ISR, you have to clear the PinInterrupt and set a flag.
7. In your main(), you can check the pin status only when the flag is set.
I have attached a sample code for you to get started.
The execution time will depend on the CPU clock speed.
You can also to the following documents for your better understanding:
PSoC 5LP Architecture TRM : https://www.cypress.com/file/123561/download
PSoC 5Lp regsiter TRm : http://www.cypress.com/files/psoc5lp-registers-trmpdf
Pins Component datasheet: https://www.cypress.com/file/133231/download
ISR component datasheet : https://www.cypress.com/file/130976/download
PSoC 5 LP GPIO - Application Note :https://www.cypress.com/file/45381/download
PSoC 5LP Interrupts - Application Note: https://www.cypress.com/file/44256/download
Code Examples: https://www.cypress.com/file/44251/download
Hope this helps! Please let us know in case you have further clarifications.
PSoC 58LP.cyprj.Archive01.zip 502.8 K