Nano ile PWM üretimi
  • 1,96 Nm, Vmax 60V, Imax 12.5 A DC motoru, Pololu PL1456 24V23A sürücü kartı ile PWM üzerinden sürmek istedim. Yaptığım çalışma sonrasında Nano timer ve OC0B/OC0A registerleri üzerinden pwm üretip motoru sürdüm. Çalışmayı paylaşmak istedim. Referanslar : https://www.pololu.com/docs/0J15/5 https://www.projehocam.com/arduino-hizli-cizgi-izleyen-robot/comment-page-1/ Saygılarımla. // **** ilk iki satır HTML yapısından dolayı çıkmıyor. include dan sonra **** // küçük işareti avr/io.h büyük işareti // küçük işareti util/delay.h büyük işareti olacak #include <avr/io.h> #include <util/delay.h> // uses F_CPU to achieve us and ms delays // DC Motor Speed Cont. #define DCmotor_PWMH 5 // Nano OC0B #define DCmotor_DIR 6 // Nano OC0A int pwm_val=0; int desired_RPM; //user selects void setup() { Serial.begin(19200); // Serial Comm. motors_init(); } // DC motor Vmax=60, Imax 6A 824 RPM/sec max. // Used 24VDC seperate Vin // RPM checked with digital tachometer void loop() { desired_RPM=250; pwm_val = map(desired_RPM,0,824,0,255); M1_forward(255-pwm_val); // motor 1 forward delay_ms(7500); desired_RPM=600; pwm_val = map(desired_RPM,0,824,0,255); M1_forward(255-pwm_val); delay_ms(7500); M1_forward(0); // motor 1 forward at FULL speed delay_ms(7500); }//loop // Motor Control Functions -- pwm is an 8-bit value // (i.e. ranges from 0 to 255) void M1_forward(unsigned char pwm) { OCR0A = 0; OCR0B = pwm; } void M1_reverse(unsigned char pwm) { OCR0B = 0; OCR0A = pwm; } // Motor Initialization routine -- this function must be called // before you use any of the above functions void motors_init() { // configure for inverted PWM output on motor control pins: // set OCxx on compare match, clear on timer overflow // Timer0 and Timer2 count up from 0 to 255 TCCR0A = 0xF3; // use the system clock/8 (=2.5 MHz) as the timer clock TCCR0B = 0x02; // initialize all PWMs to 0% duty cycle (braking) OCR0A = OCR0B = 0; // set PWM pins as digital outputs (the PWM signals will not // appear on the lines if they are digital inputs) DDRD |= (1 << PORTD3) | (1 << PORTD5) | (1 << PORTD6); DDRB |= (1 << PORTB3); } // delay for time_ms milliseconds by looping // time_ms is a two-byte value that can range from 0 - 65535 // a value of 65535 (0xFF) produces an infinite delay void delay_ms(unsigned int time_ms) { // _delay_ms() comes from <util/delay.h> and can only // delay for a max of around 13 ms when the system // clock is 20 MHz, so we define our own longer delay // routine based on _delay_ms() unsigned int i; for (i = 0; i < time_ms; i++) _delay_ms(1); }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Açık kaynak kültürü gereği, çözdüğünüz problemlerin çözümlerini paylaşmayı lütfen unutmayın.