not defined in scope only for certain boards


so running arduino 2:1.0.5 on debian laptop, , have massive hangup.

i wrote code , have running on arduino uno, yay.  i tried run on clone project , wouldn't complie.  at first assumed user error (copy pasted old versoin of code) know sure not compiling when select nano target board.

the sketch consists of 2 files, posted in entirety here. says functions in second file out of scope when compileing nano w/ 328, compiles fine mega.  it won't compile uno swear running in old unit, has uno, arduino bug or there subtle missing?  please help, super late getting little demo , running friend.

i assume has defines on serial in sthe smc area, kludge, please going on here.  i tried find , replace serial , still won't compile.  there massive amount of vestigal code in there due super rushed attempt cobble 2 working old examples.

i deleted many unused isrs left out w/ #ifdef statements, otherwise code verbatim

main file


oops, lost code,

main file
code: [select]
#include <arduino.h>
#include <timerhelpers.h>
#include "digitalwritefast.h"

//minimal code run 2 steppers
//using timer controlled pin, no isr
//
//uses timers 1 , 2
//          1a  1b           2a  2b
//sanguino: d13 d12        $ d15 d14
//mini:     d9  d10        $ d11 d3
//mega      d11 d12 d13    $ d10 d9
//
//adding second output pin phase locked
//for use second motor slaved first

  #ifndef cbi
  #define cbi(sfr, bit) (_sfr_byte(sfr) &= ~_bv(bit))
  #endif
  #ifndef sbi
  #define sbi(sfr, bit) (_sfr_byte(sfr) |= _bv(bit))
  #endif

  // modes of operation select 1
  #define continuous          //simply run continuosly

// change pulse pins based on board
#if defined(__avr_atmega1280__) || defined(__avr_atmega2560__)
byte step1 = 11;  //pb5/d11 mega
byte step1b = 8; //slave motor step pin
byte step2 = 10;
#define serial_out serial
#endif
#if defined(__avr_atmega328p__) || defined(__avr_atmega168__)
byte step1 = 9;  //pb1/d9 mini
byte step1b = 8;
byte step2 = 11;
#define serial_out serial
#endif

const byte dir1  = 10;
const byte dir2  = 12;
const byte enable = 13; //13 on mini in rig
const byte enablerxpin = 3; // pin rx, check num
const byte isrflagpin = 16;
const byte isrintflagpin = 17;
const byte speedpin1 = a4;
const byte speedpin2 = a5;

const byte guagepin1 = a0;
const byte guagepin2 = a1;

const int numstepsperrev1 = 200*17/34; //dumb luck, 100
const int numstepsperrev2 = 200;
int microsteps1 = 4;
int microsteps2 = 16;
const unsigned int traingearing1 = 5; //ratio of fast , slow motors
const unsigned int traingearing2 = 1;

const unsigned int maxturns1 = 100; //max num turns before action
const unsigned int maxturns2 = 10; //max num turns before action
const unsigned long maxsteps1 = 100; //max steps before action
const unsigned long maxsteps2 = 27.78*200; //max steps before action

//*******************************
// end variables             ****
//*******************************

volatile unsigned int ocr1ahold = 65200; //try protect updates
volatile unsigned int ocr2ahold = 200;

const unsigned long maxusteps1 = maxsteps1*microsteps1;   //takes math out of isr
const unsigned long maxusteps2 = maxsteps2*microsteps2;   //takes math out of isr
const unsigned int numustepsperrev1 = numstepsperrev1*microsteps1;
const unsigned int numustepsperrev2 = numstepsperrev2*microsteps2;

unsigned int ustepselapsed1 = 0;
unsigned int ustepselapsed2 = 0;
int rotelapsed1 = 0;     //ideally ccw or useful direction
int rotelapsed2 = 0;

boolean invertflag = false;
boolean timetoprint = true;
boolean timeupdateocr = true;
unsigned int printdelay = 5000; //millis between prints
unsigned long lastprint = 0;
unsigned int ocrdelay = 500; //millis between speed updates
unsigned long lastocr = 0;

int smcspeedsetting = 0; //-3200 3200 speed setting

float guageval1 = 0;
float guageval2 = 0;
float guagescale1 = 127.1172;
float guagescale2 = 127.1172;

unsigned int rxrefresh = 10; // time between checks of rx command
unsigned int rxrefreshdelay = 50;
static unsigned int pumpenablerx = 1500; //micros of rx flag
boolean pumpenable = false;

void serialocraset();
void sensors(byte cnt, boolean cal);

void setup(){
  serial_out.begin(19200);
  pinmode(enable, output);
  pinmode(dir1, output);
  pinmode(dir2, output);
  pinmode(step1, output);           //sets pin output
  pinmode(step2, output);
  pinmode(step1b, output);
  pinmode(isrflagpin, output);
  pinmode(isrintflagpin, output);
  digitalwrite(step1, high);
  digitalwrite(step1b, high);
  digitalwrite(step2, high);
  digitalwrite(dir1, low);
  digitalwrite(dir2, high);
  digitalwrite(enable, high);  //active low stepper drivers

  pinmode(enablerxpin, input);

   // setup stepper 1 on 1a using library
  timer1::setmode(4, timer1::prescale_256, timer1::toggle_a_on_compare);
  timer2::setmode(2, timer2::prescale_256, timer2::toggle_a_on_compare);

  ocr1a = 65000;
  ocr2a = 220;

  //enable interrupts
  sbi(timsk1, ocie1a);
  sbi(timsk2, ocie2a);

  smcsetup();
}

void loop(){
  if((millis() - lastprint) > printdelay) timetoprint=true;
  #if defined verbose_serial
  if(timetoprint){    // print useful somewhere
  }
  #endif

  if((millis() - lastocr) > ocrdelay) timeupdateocr=true;
  // if(timeupdateocr && serial.available()>3){
  if(timeupdateocr){
    timeupdateocr=false;
    lastocr=millis();
    //serialocraset();
    ocr1ahold = (analogread(speedpin1))/5+50;
    ocr2ahold = (analogread(speedpin2))/5+13;
    smcspeedsetting = map(analogread(speedpin2), 0, 1023, 3200, 0);
    setmotorspeed(smcspeedsetting);
  }
  sensors(3, false);

  // check rc input turn on/off pump
  if(rxrefresh < millis()) {
    pumpenablerx = pulsein(enablerxpin, high, 250000); // 40hz?
    rxrefresh = millis() + rxrefreshdelay;
  }
  // if on halfway reasonably valid, enable pump
  if(pumpenablerx>1500 && pumpenablerx<2500) pumpenable = true;
  else if(pumpenablerx<=1500 && pumpenablerx>800) pumpenable = false;
  else if(pumpenablerx==0) pumpenable = false; // if no pulse found, assume bad things

  if(pumpenable) digitalwrite(enable, low); // low enable
  if(!pumpenable) {
    digitalwrite(enable, high); // shut down
    motorbrake(10);             // send 10 of 32 motor brake command
  }
}

void serialocraset(){
  ocr1ahold = serial.parseint();
  ocr2ahold = serial.parseint();
  serial_out.print("ocr1ahold = ");
  serial_out.println(ocr1ahold);
  serial_out.print("ocr2ahold = ");
  serial_out.println(ocr2ahold);

}

void sensors(byte cnt, boolean cal)  {
  static float offset1 = 36;
  static float offset2 = 60;

  float pavg1 = analogread(guagepin1);
  float pavg2 = analogread(guagepin2);

  (byte = 1; i<cnt; i++){
    pavg1+=analogread(guagepin1);
    pavg2+=analogread(guagepin2);
    //delay(5); questionable
  }

  float pin1=pavg1/cnt; //0-1024
  float pin2=pavg2/cnt;

  pin1-=offset1;
  pin2-=offset2;

  //pressure = constrain(pin/pressure_sensitivity, 0, 100);
  guageval1 = pin1/guagescale1;
  guageval2 = pin2/guagescale2;

  if(cal) {
    offset1 = guageval1*guagescale1;
    offset2 = guageval2*guagescale2;
  }
}

#ifdef continuous
  isr(timer1_compa_vect){
    // #ifdef isr1amarker
    // digitalwritefast(isrflagpin, high);
    // #endif
    // gearing steps has been hit, note code works if
    // usteps per turn multiple of train gearing
    if ((ustepselapsed1 % traingearing1) == 0){digitalwritefast(step1b, high);}
    else {digitalwritefast(step1b, low);}
            //only increments every other time
    if (digitalreadfast(step1) == high){
      ustepselapsed1++;
      ocr1a = ocr1ahold;
      if (ustepselapsed1 == numustepsperrev1){  //full turn has been completed
        // #ifdef isr1amarker
        // digitalwritefast(isrintflagpin, high); //show inside if() loop
        // #endif
            //reset step counter
        ustepselapsed1 = 0;
            //increment total turns
        rotelapsed1 += 1;
      }
    }
  }

  isr(timer2_compa_vect){
    #ifdef isr2amarker
    digitalwritefast(isrflagpin, high);
    #endif
            //only increments every other time
    if (digitalreadfast(step2) == high){
      ustepselapsed2++;
      ocr2a = ocr2ahold;
      if (ustepselapsed2 == numustepsperrev2){  //full turn has been completed
        #ifdef isr2amarker
        digitalwritefast(isrintflagpin, high); //show inside if() loop
        #endif
            //reset step counter
        ustepselapsed2 = 0;
            //increment total turns
        rotelapsed2 += 1;
      }
      #ifdef isr2amarker
      digitalwritefast(isrintflagpin, low);
      #endif
    }
    #ifdef isr2amarker
    digitalwritefast(isrflagpin, low);
    #endif
  }

#endif


Arduino Forum > Using Arduino > Programming Questions > not defined in scope only for certain boards


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts