How to mimic the PulsIn() function from arduino into PSoC Creator (PSoC LP5)

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

cross mob
lock attach
Attachments are accessible only for community members.
user_3678521
Level 3
Level 3
5 likes given First like given

Hello,

I'm making a color sensor (TCS3200), and i have a issue trying to make a function that works the same way as pulsin() from arduino.

In a code i take my output value like this on arduino: PulsIn() function definition from arduino 

  // Reading the output frequency

  greenFrequency = pulseIn(sensorOut, LOW);

and i have to do somthing like that on PSoC creator.

Right now i only get 0 and 1 as output (the value of what i set my pins to).

rgb.JPG

in the attached code you can see what im trying to do.

Thanks

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

The PulsIn() seems to be a frequency counter.

The following document seems to be very helpful.

http://www.cypress.com/file/144696/download

I also tried this with PSoC 5LP board, as I don't have the sensor

I fed the pulse from my funcgen program with another MCU

via Pin P6[6] as SensorOut.

It is measuring frequency (Hz), so probably you need to adjust counter parameters.

TeraTermLog.JPG

Attached is my test project based on your project.

I hope this can be a little help.

moto

View solution in original post

5 Replies
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Hi,

There is no direct replacement for PulseIn Function in Creator.

You may have to use a GPIO and Timer  or PWM and interrupt to implement similar functionality.

These links may be useful:

Reading From an Output Pin

Read data from input pin

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

The PulsIn() seems to be a frequency counter.

The following document seems to be very helpful.

http://www.cypress.com/file/144696/download

I also tried this with PSoC 5LP board, as I don't have the sensor

I fed the pulse from my funcgen program with another MCU

via Pin P6[6] as SensorOut.

It is measuring frequency (Hz), so probably you need to adjust counter parameters.

TeraTermLog.JPG

Attached is my test project based on your project.

I hope this can be a little help.

moto

I can see that you use the:

volatile uint32_t dummy;

what is this variable used for?

Because its set but not used.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Actually it was a little bit difficult for me to use these two counters.

During the debug, when the loop timeout-ed, I wanted to check the

frequency count without overwriting the real value, so I used dummy.

Then as you noticed, as I did not use dummy anywhere else,

the compiler optimized the variable so I could not see the value

from the debugger. Then I used "volatile" key word to prevent the

compiler to opt-out the variable.

Anyway, now it does not affect anything else... I hope.

moto

Thanks for the fast respons btw, it REAALY helped me alot

0 Likes