Quantcast
Channel: Motor drivers forum - Recent Threads
Viewing all articles
Browse latest Browse all 14309

DRV2605L: PWM modulation

$
0
0
Part Number: DRV2605L

Hello, 

Using DRV2605L to control LRA motor, I want to change the amplitude-like sine function (fading up & down within 100ms). I think PWM duty cycle modulation 

could change the amplitude. Because I want to design an amplitude-changing pattern within a specific time (100ms), I used  timer interrupt registers (Arduino). 

However, the amplitude didn't change anymore. 

Here is the code: (I hope it could help you understand) 

#include<Wire.h>
#include<Sparkfun_DRV2605L.h>
#define HMD_ADDR 0x5A

SFE_HMD_DRV2605L HMD;

constint analogOutPin = 9;
volatileint pwmvalue = 0;
volatileint direction = 10;

voidsetupTimer1() {
  noInterrupts();
  // Clear registers
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;

  // 1000 Hz (16000000/((249+1)*64))
  OCR1A = 249;
  // CTC
  TCCR1B |= (1<< WGM12);
  // Prescaler 64
  TCCR1B |= (1<< CS11) | (1<< CS10);
  // Output Compare Match A Interrupt Enable
  TIMSK1 |= (1<< OCIE1A);
  interrupts();
}

voidsetup(){
  Wire.begin();
  HMD.begin();
  HMD.Mode(0x03);
  HMD.writeDRV2605L(OVERDRIVECLAMP_REG,0xFF);
  HMD.writeDRV2605L(CONTROL3_REG,0xA1);
  HMD.MotorSelect(0x86); // Related to Feedback Control (Address : 0x1A)
  HMD.Library(6);
  pinMode (analogOutPin,OUTPUT);
  setupTimer1();

}

voidloop(){}

voidpwmStep(){
  analogWrite(analogOutPin, pwmvalue);
  pwmvalue += direction;

  if (pwmvalue==0){
    direction=10;
  }
  if(pwmvalue==255){
    direction=-10;
  }
}

ISR(TIMER1_COMPA_vect) {
 
    pwmStep();
 
   
 
}
To use timer interrupt registers, are there anything to consider ?

Viewing all articles
Browse latest Browse all 14309

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>