Code

Project: Box2D_friction_mod

test_TopDownCar.py      WheelConstraint.h      test_TopDownFrictionJoint.py      box2d_friction_joint.patch      b2FrictionJoint.h      TopDownCar.h      b2FrictionJoint.cpp      TestEntries.cpp      python_friction_joint.patch     

Project: jvfeatures

jvtypes.h      jvtypes.cpp      jvfeatures.h      chessSeg.cpp      jvtest.cpp      jvfeatures.cpp     

Project: Other

migrateMailbox.scpt.txt     

Project: Infinite HMM Tutorial

HMMProblem.m      HMM.m      README.txt      HDP.m      HDP_HMM.m      run.m      iHMM_tutorial.zip      ConditionalProbabilityTable.m     

Project: Arduino_Code

arduino-serial.c      Arduino_Code.zip      convert_range2D.py      plot_ardunio_data.sh      oscilloscope.pde      oscilloscope.sh      ranger_test.pde      accelerometer_test.pde      pwm_manual.pde      servo_test.pde      motordriver.pde      ranger_plane_sweep.pde      helicopter_controller.pde      clodbuster_controller.pde     

Project: RRT

BidirectionalRRT.cpp      RRT.tgz      AbstractRRT.cpp      RRT.h      RRT.cpp      rrt_test.cpp      plot_output.py     

Project: ArduCom

arducom.py      setup.py     

Project: Dirichlet Process Mixture Tutorial

EM_GM.m      DP_Demo.m      DP_Tutorial.zip      DirichletProcess.m      DPMM.m      gaussian_EM.m     

Project: support

Protector.php      geshi.php     

Project: Cogent

CodePane.php      Cogent.php      NotesPane.php      PubsTable.php      PicsPane.php     
Click here to download "resources/code/Arduino_Code/pwm_manual/pwm_manual.pde"

resources/code/Arduino_Code/pwm_manual/pwm_manual.pde

/* Manual PWM without delay()
 
 Turns on and off a digital pin to generate a PWM signal, without
 using the delay() function.  This means that other code
 can run at the same time without being interrupted by the PWM code.
 
 Instead of using delay() calls, this code uses millis/micros calls
 to check the time since the Arduino began running the current program.
 This allows the pwm call to be non-blocking, but at the risk of a
 missed deadline for switching states.  
 
 Currently implemented to provide high resolution by using micros()
 rather than millis().  
 
 created 2009
 by Jon Scholz
 */


// {
#define PWMPERIOD 20000  // period (20 ms)

/* Pulse Width, in microseconds
 *   -Must make this a long if a period longer than 32ms is desired!
 */

unsigned int pw = 0;

/* Container for time variable
 *   -Must make this a long if a period longer than 32ms is desired!
 */

unsigned int previousMicros;

/* Current state of the PWM pin
 */

int pwmState = LOW;
// }

unsigned int pstep = 100;  // pulse width step in microseconds

char buf[32];

/*
frequency is 1/PWMPERIOD Hz
 
 */


void setup() {
  Serial.begin(9600);
  // {
  pinMode(6, OUTPUT);
  previousMicros = micros();
  // }
}

void loop() {

  if (Serial.available() > 0) {
    int inByte = Serial.read();

    switch (inByte) {
    case '+':  
      pw += pstep;
      sprintf(buf,"Setting pulse width to %d us", pw);
      Serial.println(buf);
      break;
    case '-':    
      pw -= pstep;
      sprintf(buf,"Setting pulse width to %d us", pw);
      Serial.println(buf);
      break;
    case '1':
      pstep -= 50;
      sprintf(buf,"Setting pulse step to %d", pstep);
      Serial.println(buf);
      break;
    case '2':    
      pstep += 50;
      sprintf(buf,"Setting pulse step to %d", pstep);
      Serial.println(buf);
      break;
    default:
      // whatever
      break;
    }
  }

  pulseOut(6, pw);

}

void pulseOut(int pinNumber, int pulseWidth) {
  /* Uses a millis() call to check clock so that we can run
   * a non-blocking PWM (delay calls hold up everything
   * except interrupt-driven code)
   */

   static int interval = 0;

  if (micros() - previousMicros > interval) {
    previousMicros = micros();  
    if (pwmState == LOW) {
      pwmState = HIGH;
      interval = pulseWidth;
    } else {
      pwmState = LOW;
      interval = PWMPERIOD - pulseWidth;
    }
    digitalWrite(pinNumber, pwmState);
  }
}

 

About me

Pic of me