Hoi,
Ik zou graag met behulp van een PIC de tijd tussen 2 pulsen meten. Wat is de beste manier om dit te doen?
Ik zou de PIC vanaf de startpuls bvb 1ms kunnen laten wachten endan de variabele teller + 1 doen. Dit zou dan zo doorgaan tot de stoppuls gegeven word. Daarna kan ik aan de waarde van de variabele zien hoeveel ms er verstreken is tussen de pulsen.
Iemand een beter idee?
Alvast bedankt!
volgensmij gaat dat met Pulsin, moet je even controleren.
Syntax
Variable = PULSIN Pin , State
Overview
Change the specified pin to input and measure an input pulse.
Operators
Variable - a user defined variable of type bit, byte, byte array, word, word array, dword or float.
Pin - a Port.Pin constant that specifies the I/O pin to use.
State - a constant (0 or 1) or name HIGH - LOW that specifies which edge must occur before beginning the measurement.
ExampleDIM VAR1 as BYTE
Loop:
VAR1 = PULSIN PORTB.0 , 1 ' Measure a pulse on pin 0 of PORTB.
PRINT Dec VAR1 , " " ' Display the reading
GOTO Loop ' Repeat the process.Notes
Pulsin acts as a fast clock that is triggered by a change in state (0 or 1) on the specified pin. When the state on the pin changes to the state specified, the clock starts counting. When the state on the pin changes again, the clock stops. If the state of the pin doesn't change (even if it is already in the state specified in the Pulsin instruction), the clock won't trigger. Pulsin waits a maximum of 0.65535 seconds for a trigger, then returns with 0 in variable. The variable can be either a word or a byte . If the variable is a word, the value returned by Pulsin can range from 1 to 65535 units.
The units are dependant on the frequency of the crystal used. If a 4MHz crystal is used, then each unit is 10us, while a 20MHz crystal produces a unit length of 2us.
If the variable is a byte and the crystal is 4MHz, the value returned can range from 1 to 255 units of 10µs. Internally, Pulsin always uses a 16-bit timer. When your program specifies a byte, Pulsin stores the lower 8 bits of the internal counter into it. Pulse widths longer than 2550µs will give false, low readings with a byte variable. For example, a 2560µs pulse returns a reading of 256 with a word variable and 0 with a byte variable.
ff hierneer gezet, komt recht uit de help van proton IDE