10 Replies Latest reply on May 10, 2013 6:00 AM by DaKn_263916

    reading the capture value from counter

       Hi, I am trying to read the capture value of the counter when it gets interrupted by the timer, I am not able to trace where I am going wrong. So can anyone help me for getting this. I have attached the file for your reference. Basically I am trying to get he dutycycle of the PWM in terms of RPM.

        • 1. Re: reading the capture value from counter

          ... and the file?





          • 2. Re: reading the capture value from counter

             Sorry @bob, here is the file check it in the attachments

            • 3. Re: reading the capture value from counter

              Your reset pin on counter is not routed to anything ?





              • 4. Re: reading the capture value from counter

                 @danaknight, yes i have routed the reset pin of the counter to 0 but still there are some issues with the coding in the main.c, can you help me for how to read the value of counter when interrupt occours i.e. how to read capture value from counter.

                • 5. Re: reading the capture value from counter

                  The basic codeing is an api shown in datasheet -




                  uint8/16/32 Counter_ReadCapture(void)


                  Description: This function returns the contents of the capture register or the output of the FIFO (UDB only).


                  Parameters: None


                  Return Value: uint8/16/32: Current capture value. For 24-bit Counters, the return type is uint32.


                  Side Effects: None




                  Regards, Dana.

                  • 6. Re: reading the capture value from counter

                    Well, without the settings of all your usermodules it is more or less a guess:


                    isr_1 set to rising edge? in initialization something like isr_1_StartEx(YoutInterruptRoutine) executed??


                    In YourInterruptRoutine


                    uint8 Status = Counter_1_ReadStatusRegister();


                    followed by a check of FIFONEMP - bit set ?


                    *ALL* fifo-values read off?




                    To provide us with all the information so we do not have to guess would be to upload the complete project here not only a picture of the schematic.When the procect contains some disclosured material, try to build an excerpt that you may show us openly which produces the error.


                    Use the Creator-function "Create Workspace Bundle" and upload the relulting archive here.





                    • 7. Re: reading the capture value from counter

                      Can you also tell us what the problem is? Just stating 'don't see where I'm wrong' doesn't help. Do you get no result, wrong results, is the program stuck?


                      Also, with this setup you won't get the duty cycle of the PWM, just its frequency. (The duty cycle is the fraction of each PWM period during which the output is high). But 'RPM' suggests you want to get the frequency - what is it?

                      • 8. Re: reading the capture value from counter
                                @hli, actually I am trying convert the sensor pulses interfaced to the 8CY8C050 PSoC 5 kit in to RPM. For this i have used a timer and a counter combination. My aim is to get the speed of the motor in RPM from the pulses.   
                        • 9. Re: reading the capture value from counter

                          the way you have it set up should work. Just make sure it is configured at rising edge, that you have the right gate from the timer and that you reset the counter for the next reading.


                          Would like to help more but it is kind of imposible without knowing what is actually the problem, is it entering to the ISR, is it getting wrong values?, no value at all? We could only gyess without more details

                          • 10. Re: reading the capture value from counter

                            A basic approach -




                            1) Set up PWM as a gate to counter count input (basically enable), PWM positive pulse will serve


                            as counter time resolution. So 1 sec pulse high would give counter a 1 Hz resolution, 100 mS =


                            10 Hz resolution. Width of counter >= max freq to be measured. Clock to PWM and PWM period


                            set to yield PWM output high pulse width = gate period.







                            2) Add ISR to PWM out, trigger off falling edge PWM. When ISR fires set a flag. In main() test flag,


                            read counter (it is stopped because PWM output is 0 stopping counter), then reset counter. PWM,


                            when it goes high again, will automatically restart counter.




                            Regards, Dana.