Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
B-Robot on Arduino uno
11-07-2015, 06:59 PM
Post: #11
RE: B-Robot on Arduino uno
So, set the timer1 registers serving in both chips are not the same.
The Atmega328 no OCR1C register.
Therefore, we can only cater for two events (sonar excluded).

The initialization procedure:
Code:
void eX_Motors_Init(void)
{
  dir_M1 = 0;
  dir_M2 = 0;
  TCCR1A = 0;
  TCCR1B = B00000010;
  TCCR1C = 0;
  OCR1A  = ZERO_SPEED;
  OCR1B  = ZERO_SPEED;
  TCNT1  = 0;
  TIMSK1 = B00000110;
  digitalWrite(MOTORS_ENABLE_PIN,HIGH);
}

and interrupts
Code:
ISR(TIMER1_COMPA_vect)
{
  if (dir_M1==0) return;
  if (dir_M1>0)
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor1)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor1)
  }
  OCR1A  = OCR1A + period_M1;
    __asm__ __volatile__ (
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop");
  digitalWrite(MOTOR1_STEP_PIN,HIGH);           // STEP MOTOR 1
  delay_1us();  
  digitalWrite(MOTOR1_STEP_PIN,LOW);
}

ISR( TIMER1_COMPB_vect )
{
  if (dir_M2==0)    return;
  if (dir_M2>0)
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor2)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor2)
  }
  OCR1B  = OCR1B + period_M2;
      __asm__ __volatile__ (
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop");
  digitalWrite(MOTOR2_STEP_PIN,HIGH);           // STEP MOTOR 2
  delay_1us();  
  digitalWrite(MOTOR2_STEP_PIN,LOW);
}

Since we control pins in software, you can select any of the available pins.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
B-Robot on Arduino uno - MaxMagic1986 - 11-03-2015, 07:54 PM
RE: B-Robot on Arduino uno - JohnQ - 11-05-2015, 04:04 PM
RE: B-Robot on Arduino uno - sasa999 - 11-05-2015, 04:44 PM
RE: B-Robot on Arduino uno - legin.37 - 11-05-2015, 08:59 PM
RE: B-Robot on Arduino uno - sasa999 - 11-05-2015, 10:48 PM
RE: B-Robot on Arduino uno - legin.37 - 11-06-2015, 09:13 AM
RE: B-Robot on Arduino uno - sasa999 - 11-06-2015, 09:21 AM
RE: B-Robot on Arduino uno - legin.37 - 11-06-2015, 10:22 AM
RE: B-Robot on Arduino uno - michael_s - 12-20-2015, 06:40 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-06-2015, 09:47 AM
RE: B-Robot on Arduino uno - KomX - 11-06-2015, 11:10 AM
RE: B-Robot on Arduino uno - KomX - 11-07-2015 06:59 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 01:16 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 02:32 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 05:00 PM
RE: B-Robot on Arduino uno - KomX - 11-09-2015, 06:38 PM
RE: B-Robot on Arduino uno - sasa999 - 12-20-2015, 09:15 PM
RE: B-Robot on Arduino uno - michael_s - 12-22-2015, 09:18 AM
RE: B-Robot on Arduino uno - KomX - 12-22-2015, 10:06 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)