reading the capture value from counter

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 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.

0 Likes
1 Solution
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Your reset pin on counter is not routed to anything ?

   

 

   

View solution in original post

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

... and the file?

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Your reset pin on counter is not routed to anything ?

   

 

   

0 Likes
Anonymous
Not applicable

 @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.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

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?

0 Likes
Anonymous
Not applicable
        @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.   
0 Likes
Anonymous
Not applicable

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes