PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
wiring_pulse.c
Go to the documentation of this file.
1 
9 #include <Arduino.h>
10 
11 static const int Us = 1000000;
12 
13 static int32_t Pulsin_clk(int32_t Pin, int32_t State)
14 {
15  int32_t Duration = 0;
16  DIRA &= ~(1<<Pin);
17  CTRA = 0;
18  if (State == 1) {
19  CTRA = (0x68800000 | Pin);
20  } else {
21  CTRA = (0x54800000 | Pin);
22  }
23  FRQA = 1;
24  waitpne((State << Pin), ((1<<Pin)));
25  PHSA = 0;
26  waitpeq((State << Pin), ((1<<Pin)));
27  waitpne((State << Pin), ((1<<Pin)));
28  Duration = PHSA;
29  CTRA = 0;
30  return Duration;
31 }
32 
33 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
34 {
35  int32_t Duration = 0;
36  Duration = (((Pulsin_clk(pin, state) / Us) / 2) + 1);
37  return Duration;
38 }
39 
40 void pulseOut(uint8_t pin, unsigned long duration)
41 {
42  digitalWrite(pin, HIGH);
43  duration = max(duration - 20, 1);
44  delayMicroseconds(duration);
45  digitalWrite(pin, LOW);
46 }
waitpeq
#define waitpeq(state, mask)
Wait until INA equal state & mask.
Definition: propeller.h:190
PHSA
#define PHSA
Counter A phase accumulation register.
Definition: propeller1.h:173
FRQA
#define FRQA
Counter A frequency register.
Definition: propeller1.h:169
timeout
int timeout(int time)
Compares the time against the time elapsed since mark (deprecated).
Definition: timeout.c:19
Arduino.h
Provides Arduino types and functions on the Propeller.
waitpne
#define waitpne(state, mask)
Wait until INA not equal state & mask.
Definition: propeller.h:197
DIRA
#define DIRA
Use to set pins to input (0) or output (1).
Definition: propeller1.h:161
CTRA
#define CTRA
Counter A control register.
Definition: propeller1.h:165