running small motors with pic® microcontrollers

4
RUNNING SMALL MOTORS WITH PIC® MICROCONTROLLERS Harprit Singh Sandhu New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto

Upload: others

Post on 15-Feb-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RUNNING SMALL MOTORS WITH PIC® MICROCONTROLLERS

RUNNING SMALL MOTORS WITH PIC®

MICROCONTROLLERS

Harprit Singh Sandhu

New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul

Singapore Sydney Toronto

Page 2: RUNNING SMALL MOTORS WITH PIC® MICROCONTROLLERS

CONTENTS

Preface xiii

PART I Microcontrollers 1

Chapter 1 Introduction to microEngineering Labs' LAB-X1 Experimental Board 3

Chapter 2 Getting Started 13 The Hardware and Software 13 The Programmers 14 Loading the Software 15

Chapter 3 Understanding the Microchip Technology PIC 16F877A: Features of the MCU 19

Chapter 4 The Software, Compilers, and Editors 33 Basic Compiler Instruction Set 33 PICBASIC PRO Compiler Instruction Set 35 PICBASIC PRO Compiler 39 PICBASIC PRO Tips and Cautions 41

Chapter 5 Controlling the Output and Reading the Input 43 Generating Outputs 44 The LCD Display 48 Writing Binary, Hex, and Decimal Values to the LCD 52 Exercises 75

Chapter 6 Timers and Counters 79 Timers 80 The Watchdog Timer 101 Counters 101 Pre-scalers and Post-sealers 108 Timer Operation Confirmation 109 Exercises for Timers 109 Exercises for Counters 109

ix

Page 3: RUNNING SMALL MOTORS WITH PIC® MICROCONTROLLERS

X CONTENTS

Chapter 7 Clocks and Memory: Sockets U3, U4, U5, U6, U7, and US 111

Sockets U3, U4 and U5: For Serial One Wire Memory Devices 111 Socket U6: Real Time Clocks 118 Sockets U7 and U8 124

Chapter 8 Serial Communications: Sockets U9 and U10 129 When and How Will I Know the Interface Is Working? 132 Using the RS485 Communications 135

Chapter 9 Using Liquid Crystal Displays: An Information Resource 137

Using LCDs in Your Projects 140 Understanding the Hardware and Software Interaction 140 Talking to the LCD 142 Liquid Crystal Display Exercises 152

PART II Running the Motors 157

Chapter 10 The PIC 18F4331 Microcontroller: A Minimal Introduction 159

The PIC 18F4331 Can Be Used in the LAB-X1 160

Chapter 11 Running Motors: A Preliminary Discussion 163

R/C Hobby Servo Motors 163 Stepper Motors 164 DC Motors with Attached Encoders 165 Relays and Solenoids 165 "The Response Characteristics" of a Motor 766

Chapter 12 Motor Amplifiers 169 Notes on Homemade Amplifier Construction 170 The Xavien 2-Axis Amplifier 171 The 1-Axis Xavien Amplifier 173 The Solarbotics 2-Axis Amplifier 175

Chapter 13 Running Hobby R/C Servo Motors 179 Model Aircraft Servos 180 Wiring Connections 180

Chapter 14 Running Small DC Motors with Permanent Magnet Fields 191

PWM Frequency Considerations 193 Connections to the Amplifier and Processor 193 The Software to Run the Motor 195

Page 4: RUNNING SMALL MOTORS WITH PIC® MICROCONTROLLERS

CONTENTS XI

Chapter 15 Running DC Motors with Attached Incremental Encoders 201

Changing the Processor in the LAB-X1 202 DC Servo Motors with Encoders 203 The Programs 215

Chapter 16 Running Bipolar Stepper Motors 261 Stepper Motor and Amplifier Selection 262 Running the Motor 263

Chapter 17 Running Small AC Motors: Using Solenoids and Relays 283

Running a Motor 284 Using a Relay 285

Chapter 18 Debugging and Troubleshooting 287 Problem: The Microcontroller Crystal Circuit Must Oscillate 287 Using the PBP Compiler Commands to Help Debug a Program 290 Debugging at the Practical Level 292 Configuring the 16F877A and Related Notes 295 Questions and Answers 296 Settings 298

Chapter 19 Conclusion 303

PART III Appendixes 305

Appendix A Setting up Compiler for One Keystroke Operation 307

Appendix В Abbreviations Used in

the Book and in the Data Sheets 309

Appendix С The Book Support Web Site 313

Appendix D Sources of Materials 315 Controller from Encodergeek.com 316

Appendix E Motor Control Language: Some Minimal Ideas, Guidance, and Notes 321

Language Commands 321 Interrogation 322 An Industrial Language Used by CNC Machines 323

Index 327