Input Capture on jm128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Input Capture on jm128

795 Views
carlospalma
Contributor I

Hello everybody, I'm working on a project which requires using HC SR04 ultrasonic

ranging module, but I'm stuck using the sensor since I can't seem to make the

Input Capture work using processor expert. So far I have used this:

void Cap1_OnCapture(void)

{

  /* Write your code here ... */

if(Cap1_GetCaptureValue(&pulse)==ERR_OK)

    {

  Bit2_NegVal();

  Cap1_Reset();

    }

}

so if an event of getting the value of the timer when an edge is detected occurs, a Led is supposed

to change its state. Problem is that even though the Led blinks, when I try to see the value of the

variable pulse using a serial communication, I get its initial value (200) in this case, which means that the

event didn't change it!

Any help would be greatly appreciated.

0 Kudos
Reply
1 Reply

441 Views
carlospalma
Contributor I

Well, I am in the way of  solving this and wanted to share my advances. As I said before for some reason the serial communication of the value acquired by the function Cap1_GetCaptureValue showed always 0. So I changed the routine to be this:

void Cap1_OnCapture(void)

{

  /* Write your code here ... */

pulse=TPM1C2V;

Bit2_NegVal();

}

and boilá!, now when I use a PWM signal as the input to the Input capture and configure it to both edges, if I select the pulse width to be 50 us, I get 51 from the serial communication. (it gets the pulse width correctly), I have tried different values in microseconds and the value is always close (100-106), however the led is blinking oddly, many times more than it should.

0 Kudos
Reply