PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
pulseOut.c
1 /*
2  * @file pulseOut.c
3  *
4  * @author Andy Lindsay
5  *
6  * @version 0.85
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2012. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief pulseOut function source, see simpletools.h for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 #include "simpletools.h" // simpletools function prototypes
18 
19 void pulse_out(int pin, int time) // pulseOut function definition
20 {
21  /*
22  if(st_iodt == 0)
23  {
24  set_io_dt(CLKFREQ/1000000);
25  set_io_timeout(CLKFREQ/4);
26  }
27  */
28  signed long phsVal = -time * st_iodt;
29  //int ctr = 0;
30  int frq = 1;
31  int phs = 0;
32  int state = get_output(pin);
33  if(state == 1)
34  {
35  phsVal = -phsVal;
36  phs = -1;
37  frq = -1;
38  }
39  if (CTRA == 0)
40  {
41  PHSA = phs;
42  FRQA = frq;
43  CTRA = pin;
44  CTRA += (4 << 26);
45  low(pin);
46  PHSA = phsVal;
47  while(get_state(pin) != state);
48  set_output(pin, state);
49  CTRA = 0;
50  }
51  else if (CTRB == 0)
52  {
53  PHSA = phs;
54  FRQA = frq;
55  CTRA = pin;
56  CTRA += (4 << 26);
57  low(pin);
58  PHSA = phsVal;
59  while(get_state(pin) != state);
60  set_output(pin, state);
61  CTRA = 0;
62  }
63 }
64 
PHSA
#define PHSA
Counter A phase accumulation register.
Definition: propeller1.h:173
low
void low(int pin)
Set an I/O pin to output-low.
Definition: low.c:19
FRQA
#define FRQA
Counter A frequency register.
Definition: propeller1.h:169
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
pulse_out
void pulse_out(int pin, int time)
Transmit a pulse with an I/O pin.
Definition: pulseOut.c:19
get_state
unsigned int get_state(int pin)
Check the state of an I/O pin without setting it to input.
Definition: getState.c:19
CTRB
#define CTRB
Counter B control register.
Definition: propeller1.h:167
st_iodt
int st_iodt
Clock ticks in a time increment used by pulse_in, pulse_out, and rc_time. Default value is the number...
Definition: timeTicks.c:24
get_output
unsigned int get_output(int pin)
Get I/O pin output state.
Definition: getOutput.c:19
set_output
void set_output(int pin, int state)
Set I/O pin output register bit to either 1 or 0.
Definition: setOutput.c:19
CTRA
#define CTRA
Counter A control register.
Definition: propeller1.h:165