Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: rotary encoder project: troublesooting on: August 31, 2013, 09:57:07 am
motor works when is directly connected to power supply 9V.
So what about encoder? Wrong connections?

Btw i have done the part 1 of my project. I have to make it count position with interrupts. So i think connection of the encoder with arduino board is ok.
2  Using Arduino / Project Guidance / rotary encoder project: troublesooting on: August 31, 2013, 09:35:17 am
Hello,
i am doing a project with arduino and a rotary encoder from a HP injekt printer.

The wire connections are the followings

The problem is when i connect the wire from the pin of sn754410 to the +9v wire of the dc transformer i have sparks and dc motor doesnt work..
3  Using Arduino / Programming Questions / Re: pwm with phase correct on: February 10, 2013, 12:24:29 pm
because i have to find the correct pwm frequency of this code. I don't have oscilloscope and it's my first time that i m doing this. That's why i asked what's the TOP in this code. (255 or 128?)
4  Using Arduino / Programming Questions / pwm with phase correct on: February 10, 2013, 12:01:51 pm
Hey guyz,
i 'm trying to write a code to drive a dc motor. I don't care about the freq but i want good resolution. So i found that phase correct is a good choice to drive dc motors and timer 2 is my choice. My question is that i cant understand how to set the TOP. I read that you can set it through OCRnA but in another article i read that 255 is the fixed value in phase correct. I am asking this because i want to find the pwm frequency. Isn't PWM_frequency = clock_speed / (2 * Prescaller_value * TOP_value ) the right equation?
here is my code:

Code:
#include <avr/io.h>


int main(void)
{
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);

    OCR2A = 128;
    // set PWM for 50% duty cycle


    TCCR2A |= (1 << COM2A1);
    // set none-inverting mode

    TCCR2A |= (0 << WGM21) | (1 << WGM20);
    // set phase-correct PWM Mode

    TCCR2B |= (1 << CS20);
    // set no prescaler and starts PWM


    while (1);
    {
    }
}
5  Using Arduino / Programming Questions / 40khz output using fast-pwm on: November 20, 2012, 03:24:19 am
Good morning,
i wrote a code to drive a dc motor(right and left) with potensiometer.
Now i have to modify this code and set the frequency 40khz and then modify the duration of pwm with the potensiometer. Could you please give me a help with that?
Code:
int potPin = 0;        
int speedPin = 3;      
int motor1Pin = 6;    
int motor2Pin = 7;    
int ledPin = 13;      
int val = 0;        
int x = 0;
void setup() {
// set digital i/o pins as outputs:
pinMode(speedPin, OUTPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}
void loop() {
digitalWrite(ledPin, HIGH);  
val = analogRead(potPin);
if (val <= 511) {
x=255-(val/2);
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
analogWrite(speedPin, x);
}
else {
  x=(val/2)-256;
digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
analogWrite(speedPin, x);  // output speed as PWM value


}
Serial.print("X: ");
                Serial.println(x, DEC);
}

Code:
void startTransducer()
{
  TCCR2A = _BV(COM2A0) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
  OCR2A = B11000111; // 199, so timer2 counts from 0 to 199 (200 cycles at 16 MHz)
}

void setup()
{
pinMode(11, OUTPUT);
startTransducer();
}

void loop()
{
}


Pages: [1]