Arduino Jaguar

This page has details on running a USFIRST FRC jaguar from an Arduino

The Adaptor Board is available at: http://www.sparkfun.com/products/9281

First step involved speed control via the serial link.

//

#include <avr/interrupt.h>

const int jagsigpin = 9; //pwm connection on pin 9

const int jagpwrpin = 7;//using pin 7 as the pwm power reference

const int jaggndpin = 8;//using pin 8 as the pwm ground reference

const int ledpin = 13;//using the standard LED as a status indicator

const int buffsize = 3;//determining the digits buffer size

char mybuffer[buffsize]; //declare an array to take input from the serial

int value = 47;// decimal 47 corresponds with the pwm midpoint

int minvalue = 20;// decimal 20 corresponds with the pwm full reverse

int maxvalue = 74; //decimal 74 corresponds with the pwm full forward

boolean ledstatus = LOW; //initialize the LED status

 

void setup()

{

  //set the PWM frequency to be 122Hz

  TCCR1B = TCCR1B & 0b11111000 | 0x04;

 //setup the pins to be used with the PWM

  pinMode(jagsigpin, OUTPUT);

  pinMode(jagpwrpin, OUTPUT);

  pinMode(jaggndpin, OUTPUT);

//setup the LED status pin

  pinMode(ledpin, OUTPUT);

//define the pwm reference voltages

  digitalWrite(jagpwrpin,HIGH);

  digitalWrite(jaggndpin,LOW);

//start the serial interface... 9600 is arbitrary

  Serial.begin(9600);

//set the pwm to midscale so the jaguar starts in a friendly state

  analogWrite(jagsigpin,value);

  

}

void loop(){

//wait for there to be something on the serial interface

  if(Serial.available()>0){

   // give time for the rest of the digits to come across

    delay(100);

  // 8bit characters (chars) come across the serial interface, each one is an ascii value

  // group these characters into a char array for processing

    for(int i =0; i<buffsize; i=i+1){

      mybuffer[i] = Serial.read();

    }

    Serial.flush();

  //use the c function "atoi" to convert the char array to a integer value

    value = atoi(mybuffer);   

  // print the value to the console

    Serial.print(value);

  //write the pwm value

    analogWrite(jagsigpin,value);

  

  //toggle the indicator

    ledstatus = ~ledstatus;

    digitalWrite(ledpin,ledstatus);

    Serial.write('\n');

  }

}

References:

Changing the Arduino PWM frequency

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4

Page 5, Table 4 has the PWM timing information

Jaguar DataSheet

Autoramp mode was necessary to not trip the overcurrent protection on my bench power supplies

Check out Q7 for Details on enabling:

AutoRamp Mode