Example 12 PulseWidth Modulation PWM Motors and Servos

  • Slides: 14
Download presentation
Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L 8. 1

Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L 8. 1

PIM_9 DP 256 Block Diagram PWM Port

PIM_9 DP 256 Block Diagram PWM Port

PWM Pins PP 0 – PP 7 Pins 4, 3, 2, 1, 112, 111,

PWM Pins PP 0 – PP 7 Pins 4, 3, 2, 1, 112, 111, 110, 109

PWM Pins PP 0 – PP 7 Pins 4, 3, 2, 1, 112, 111,

PWM Pins PP 0 – PP 7 Pins 4, 3, 2, 1, 112, 111, 110, 109

Motor Driver Circuit Solid-state relay

Motor Driver Circuit Solid-state relay

MOS FET Relays G 3 VM-61 B 1

MOS FET Relays G 3 VM-61 B 1

Motor – Generator Experiment

Motor – Generator Experiment

Using an AC Relay

Using an AC Relay

Pulse-Width Modulation

Pulse-Width Modulation

// Example 12 a: Motor demo #include <hidef. h> /* common defines and macros

// Example 12 a: Motor demo #include <hidef. h> /* common defines and macros */ #include <mc 9 s 12 dp 256. h> /* derivative information */ #include "main_asm. h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc 9 s 12 dp 256 b" void main(void) { int val; int speed; PLL_init(); // set system clock frequency to 24 MHz ad 0_enable(); // enable a/d converter 0 lcd_init(); // enable lcd motor 1_init(); // enable 8 -bit pwm 1 for motor while(1) { val = ad 0 conv(7); // 0 - 1023 speed = val >> 2; // 0 - 255 set_lcd_addr(0 x 40); // 2 nd line of lcd display write_int_lcd(speed); // display speed motor 1(speed); // set motor speed ms_delay(100); // delay 100 ms } }

Controlling the Position of a Servo using PWM

Controlling the Position of a Servo using PWM

// Example 12 b: Servo demo #include <hidef. h> /* common defines and macros

// Example 12 b: Servo demo #include <hidef. h> /* common defines and macros */ #include <mc 9 s 12 dp 256. h> /* derivative information */ #include "main_asm. h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc 9 s 12 dp 256 b" void main(void) { int val; int width; PLL_init(); // set system clock frequency to 24 MHz ad 0_enable(); // enable a/d converter 0 lcd_init(); // enable lcd servo 1_init(); // enable pwm 1 for servo while(1) { val = ad 0 conv(7); // 0 - 1023 width = (val << 1) + 3536; // width: 3536 - 5582 set_lcd_addr(0 x 40); // line 2 of lcd display write_int_lcd(width); // display width on lcd set_servo 1(width); // move servo to pos width ms_delay(100); // delay 100 ms } }