![]() | ![]() | ![]() |
| |||||||
| Robotics Chat Specific to discussions about robots and the making of. |
![]() |
| | Tools |
| | #1 |
|
Hello Is it possible to control DC motor from bytes to PIC16F628? I am struggling with this and had a look at Nigel tutorials. Thanks Bathini | |
| |
| | #2 |
|
Yes, it needs to control an H-bridge. ANd to do that you will need to generate PWM signals from your microcontroller somehow either with the built-in hardware, or bit blasting if the MCU does not have an output compare or PWM module.
| |
| |
| | #3 |
|
As you've checked my tutorials, look at the PWM one - which gives 128 speeds either forwards or backwards for two motors. As dknguyen says, you also need an h-bridge to feed the motor, and if you want to use two motors (like for a robot), a 16F628 isn't enough, and my tutorial uses a 16F876 for that reason.
| |
| |
| | #4 |
|
I have designed the following circuit ...H Bridge Circuits - The last circuit from the bottom and works but when it comes to code?I do not know. I read your tutorial and seem to understand but for my implementation it is tricky. I was going to send the bytes with this utility ..Pololu - Pololu Serial Transmitter utility for Windows - serial transmitter and turn on an LED from one of the output pin e.g RA0 before connecting the entire H-bridge.
| |
| |
| | #5 |
|
Are you wanting speed control?, or just forward and reverse?. It would be easy to use my serial and PWM tutorials to make a project that receives serial data and controls motors accordingly. | |
| |
| | #6 |
|
Hi Nigel I am trying speed control, forward, reverse and stop. My intent is send byte 1 - preamble all ones, byte 2 - address of motor, byte 3 - direction and speed(crucial one) and byte 4 - error detection. I am going back to visit your site to study your tutorials again and see what I will come with. jacks | |
| |
| | #7 |
|
From the sound of it you're wanting to do this via radio?, so my Manchester radio routines (using a two byte packet) and the PWM tutorial could easily be joined together.
| |
| |
| | #8 |
|
Wouldn't a half bridge work fine for bidirectional DC motors? What would be the advantage of a full H-bridge?
| |
| |
| | #9 |
|
A half bridge requires a split power supply.
| |
| |
| | #10 |
|
LOL, right. Sometimes it's the simple things that trip me up the most. ![]() Hence why I'm here now. | |
| |
| | #11 |
|
Friends I have been reading and referencing from Nigel tutorials and would like to know where am I making a mistake? LIST p=16F628 ;tell assembler what chip we are using include "P16F628.inc" ;include the defaults for the chip ERRORLEVEL 0, -302 ;suppress bank selection messages __config 0x3D18 ;sets the configuration settings (oscillator) cblock 0x20 ;start of general purpose registers count KM Equ 0 org 0x0000 movlw 0x07 movwf CMCON ;turn comparators off Initialise clrf count clrf PORTA clrf PORTB SetPorts bsf STATUS, RP0 ;select bank 1 MOVLW B'00000110' MOVWF TRISB bcf STATUS, RP0 ;select bank 0 call SER_INIT CHECK call Rcv_RS232 ;check receive data xorlw 'B' btfss STATUS, Z ;is data 'B'? goto CHECK ;if not, goto CHECK goto KM_ON ;if yes. goto KM_ON KM_ON bsf PORTB, KM ;ON goto CHECK :Hardware USART Serial Routines SER_INIT BSF STATUS, RP0 ;select bank 1 MOVLW d'25' ;9600 baud @ 4 Mhz Fosc +0.16% err MOVWF SPBRG MOVLW b'00100100' ;BRGH = 1 MOVWF TXSTA ;enable Async Transmission, set brgh BCF STATUS, RP0 ;select bank 0 MOVLW b'10010000' MOVWF RCSTA ;enable Async Reception RETURN XMIT_RS232 btfss PIR1, TXIF ;xmit buffer empty? GOTO XMIT_RS232 ;no, wait MOVWF TXREG ;now send RETURN Rcv_RS232 BTFSS PIR1, RCIF ;check for received data GOTO Rcv_RS232 MOVF RCREG, W RETURN ;End of serial routines ; Activating RA0 pin17 on PIC16F628 LED Equ 0 ;set constant LED = 0 LEDPORT Equ PORTA ;set constant LEDPORT = 'PORTA' org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running movlw 0x07 movwf CMCON ;turn comparators off bsf STATUS, RP0 ;select bank 1 movlw b'00000010' ;set PortB all outputs except RB1 movwf TRISB movwf TRISA ;set PortA all outputs bcf STATUS, RP0 ;select bank 0 clrf PORTA clrf PORTB ;set all outputs 0 Loop bsf LEDPORT, LED ;turn on RA0 only! call Delay ;this waits for a while! goto Loop ;go back and do it again Delay movlw d'250' ;delay 250 ms (4 MHz clock) movwf count1 d1 movlw 0xC7 ;delay 1mS movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto $+2 decfsz countb, f goto Delay_0 decfsz count1 ,f goto d1 retlw 0x00 ; PWM implementation via strobe and pin9 of PIC16F628 portb equ 0x06 ; port b equate duty equ 0x0c ; length of duty cycle temp equ 0x0d ; length of duty cycle ;--------------------------------------------------------------------- c equ 0 ; status bit to check after subtraction ;--------------------------------------------------------------------- org 0x000 movlw 0x00 ; load W with 0x00 make port B output tris portb ; copy W tristate to port B outputs movlw 0x00 ; fill w with zeroes movwf portb ; set port b outputs to low rstrt movlw d'0' movwf portb movlw d'110' ; Duty cycle length movwf duty b0loop movf duty,w movwf temp bsf portb,0 pwma nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwma movlw d'255' movwf temp movf duty,w subwf temp,f bcf portb,0 pwmb nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwmb goto rstrt ;---------------------------------------------------------------------- end | |
| |
| | #12 |
|
For a start, you've got three org 0x000 lines, so the program will be overwriting itself, assuming the assembler will even assemble it?. Also, when posting code, use the 'code' tags (from 'Go Advanced') to keep the code formatted correctly. | |
| |
|
| Tags |
| bytes, controlling, motor |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Controlling a DC Motor | diablo1 | Micro Controllers | 22 | 3rd February 2009 11:03 PM |
| Controlling a DC motor via R/C | olvidame | Robotics Chat | 1 | 22nd November 2008 01:44 AM |
| Controlling for DC motor | civictypeR | Electronic Projects Design/Ideas/Reviews | 5 | 23rd February 2008 06:05 PM |
| Motor Characteristics Graph + controlling motor | lil'gal | Robotics Chat | 2 | 29th September 2004 01:30 PM |
| Controlling a DC motor | JohnG | Electronic Projects Design/Ideas/Reviews | 5 | 5th April 2004 01:17 PM |