SMC01B IC chip controlling L298

I’m using a 16F628 to send serial data to the SMC01B IC which controls the L298 Hbridge.
I do not have the L298 hooked up in the breadboard, becuase I like to test parts of circuits first and not risk damaging anything.
Using a voltmeter I get all low outputs on the SMC01B chip. Which i believe would be the default config if no serial data was sent down the line. Although it may be becuase I have hooked up my reset line incorrectly on the SMC? (High output from PORTB, RB0 to reset)

I’m using an SPBRG of 14 which should give me around 4.1k baud with the 4MHZ internal OSC

My problem is there is not much documentation on the SMC chip itself and I’m wondering if I’ve done everything right.
Does all low outputs sound like the serial data is either not being sent or is incorrect?

I also do not understand the current sensing resistors on the L298, the datasheet seems to imply they are for measuring but that they are required… Do they control the current to the load or allow for measurement?

I will post my code if it is needed… This shouldnt be a big problem its just I have nothing to check my circuit with as there is no documentation
Thank you in advance for any help.

I don’t have any experience wiring up the SMC01B IC, so I can’t help you there, but I can tell you that you do need to connect the current sense pins (pins 1 and 15) on the L298 to gronud, either directly or through a very low-resistance resistor (with a sufficiently high power rating).

If you take a look at the block diagram on the L298 datasheet, you can see that the current sense pins are the only route for current from each H-bridge to get to ground. If you wanted to measure the current used by each motor, you could route it through low-resistance resistor, then amplify and measure the voltage drop across that resistor, which would be proportional to the current. IF you wanted to…

This is not made obvious by the datasheet and confused me for a really long time too!

-Adam

Hello,

Adam is right about the current sense lines. The documentation is limited to the motor controller kit user’s guide; the main thing is the schematic on page 15. The lines are initially low, but that’s not all that great of an indicator of anything. Once you send a good command, you should definitely see some activity on the output lines (GP0, GP1, GP2, and GP5).

- Jan

Thanks for the help guys… I’m now confident the serial controller and H bridge are connected corrrectly… I think I’ve determined its my code that isnt working…
It seems to be freezing during sending out the serial data…

This is where my variables and TX are setup

	Motor0	EQU	H'21'		; Motor0 speed
	Motor1	EQU	H'22'		; Motor1 speed
	rev0	EQU	H'23'		; Reverse flag for Motor0
	rev1	EQU	H'24'		; Reverse flag for Motor1


	count1	EQU	H'25'		; Delay Variables.
	counta	EQU	H'26'
	countb	EQU	H'27'		


	org	0x0000			;org sets the origin, 0x0000
	goto 	main			;this is where the program starts running	



	org	0x0004			;org sets the origin, 0x0004
	goto	IntH			;this is where interrupts are vectored	



main

	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)

   	bsf 	STATUS,		RP0	;set   RP0
	bcf 	STATUS,		RP1	;clear RP1	This selects Bank 1

   	movlw 	b'00000000'		;Set all ports to output
   	movwf 	TRISB
	movwf	TRISA

	bcf	INTCON, 	GIE	;Global Interrupt Disable   (clear)
	bcf	INTCON, 	INTE	;External Interrupt Disable (clear)
	bcf	INTCON, 	INTF	;External Intterupt flag





   	bcf 	STATUS,		RP0	;clear RP0
	bcf 	STATUS,		RP1	;clear RP1	This will select bank 0


; Serial transmit setup

	movlw	d'20'
	movwf	SPBRG			;Set the baud rate.

	bcf	TXSTA,		BRGH	;low speed baud rate
   	bcf	TXSTA,		TX9	;8bit transmission
	bcf	TXSTA,		SYNC	;Asynchro mode   idk?


	bcf	PIE1,		TXIE	;Interupts disabled

	bsf	TXSTA,		TXEN	;Transmit Enable bit

   	bcf 	STATUS,		RP0	;clear RP0
	bcf 	STATUS,		RP1	;clear RP1	This will select bank 0


   	bsf	RCSTA,		SPEN	;Serial Port Enable. Do I need this? sure..
	bcf	RCSTA,		RX9	;8bit receive
	bcf	RCSTA,		CREN	;Continous Receive disable


This is the code for actual sending the data to the SMC

;Serial transmit to motor controller IC

UpdateMotors				;Check to see if we want the speed changed If so Change it

updm0

	call	SerStart
	call	SerChk			; No longer needed after serial startup
	movlw	b'00000001'
	subwf   rev0,0
	movwf	TXREG
	call	SerChk
	movfw	Motor0
	movwf	TXREG
	call	SerChk

updm1

	call	SerStart
	call	SerChk			; No longer needed after serial startup
	movlw	b'00000011'
	subwf   rev1,0
	movwf	TXREG
	call	SerChk
	movfw	Motor1
	movwf	TXREG
	call	SerChk


	bsf 	PORTB,		3	;  test
	call 	Delay			; Let motor controller initialize
	call 	Delay			; Let motor controller initialize
	call 	Delay			; Let motor controller initialize
	call 	Delay			; Let motor controller initialize

	bcf 	PORTB,		3	; test
	call 	Delay			; Let motor controller initialize


	return


SerStart
	call 	SerChk
	movlw	0x80
	movwf	TXREG
	call	SerChk
	movlw	0x00
	movwf	TXREG	
;	call	SerChk
	return

SerChk
	btfss 	PIR1,		TXIF	;Test if the data has been sent from buffer
	goto	$-1			;Does this work?
	return

I believe the problem is with the way I’ve configured the serial registers

I just saw this and while I have SPEN set high… I figured pins for RX and TX should be output but this says put them as input?
I’ve tried both ways…

[quote]Bit SPEN (RCSTA<7>), and bits TRISB<2:1>, have to
be set in order to configure pins RB2/TX/CK and RB1/
RX/DT as the Universal Synchronous Asynchronous
Receiver Transmitter.[/quote]

This is where the code seems to loop… Which is understandable if the serial data is never sent…

SerChk
	btfss 	PIR1,		TXIF	;Test if the data has been sent from buffer
	goto	$-1			;Does this work?
	return

I have read carefully, but not sure what I’m doing wrong to stop the serial output? The post before this one contains more of my code for setting up the USART

Sorry to waste everyones time… It was a bank problem… I got off track of switching them back to access TXSTA

I do not have the L298 hooked up, but i’m reading M0 as seemingly working (2.5v and then jumps up to 5v?) which could be correct with the PWM, although i didnt think it affected voltage…
Motor1 is still reading GND on both pins…
I’m sending the same commands to both M0 and M1 so they should have the same outputs… I’m using motor0 and 1 and not using the default motor2 and 3.
Maybe It will be a simple fix, if not I’ll be checking back here for ideas…
Thanks guys.

I think the SMC is actually working correctly(or my code is)…
Its just the pinout that is confusing… i cant figure out how it would connect to the L298

The documentation does not show which pins are related to each other

This is the output i’m getting on the SMC:
GP1: High(1)
GP2: High(1)
GP5: LOW(0)
GP0: LOW(0)

Which according to the ducomentation seems like it would be wrong or would be braking…
But its possible that this is correct for a forward movement(or reverse?)
I cannot tell as the docs do not have anything on the Hbridge used itself…

Any help on how to hook up the outputs with the correct inputs of the L298?

Have you looked at the SN754410 datasheet? The schematic diagram shows how to hook that up, and you basically need to substitute the corresponding L298 pins for the SN754410 pins. Ys are outputs, As are inputs, and ENs are the enables. Current sensing goes to ground, logic voltage should be 5V, and supply voltage should be your motor voltage.

GP1 and GP2 are for one motor, and GP5 and GP0 are for the other. With the motor driver you’re using, both low or both high will correspond to a brake mode, and there is no coast option. When you have some speed set, the motor controller holds one pin high and PWMs the other low (which alternates between power and brake on some motor drivers instead of a power and coast).

- Jan

Thank you for your help jan… I’ve ran some more tests… Tried to fix my code a little…
I’m still seeing a weird output on the SMC…
This could be the same output as I posted earlier just more info?

Motor0
GP1: +1.5v and -4v
GP2: +5v

Motor1
GP0: -5v
GP5: -5v

I’m not sure if this is wrong or not possible or what?
I didnt think it was possible to have -+ output on one pin?
Do I assume chip malfunction?
Also, My code is alternating between 3 second pulses of forward and then reverse(forward for 3sec then reverse for 3 then repeat)

I’m getting no change of output on the SMC and I know the code is not getting stuck somewhere as I have LEDs for forward and reverse on PORTB of the IC i’m using to control the SMC.
I can only think of my code being wrong, in which case I dont know why i would get any output not to mention the output i get?
Or the chip is messed up?

That -4 V part is kind of disconcerting since there’s nothing in the chip itself that would generate -4 V, and applying -4 V to a pin can destroy the chip.

I looked at your code a bit more, and I don’t see where you’re setting the revx and Motorx values, but it seems like you’re doing something weird with the subtraction around the third byte. Sending commands to the wrong motor number would definitely explain not getting any response, so I think you should hard code in the bytes you’re sending and send the commands to motor 0 (e.g. send the bytes 0x80, 0x00, 0x00, 0x7F).

- Jan

While playing with the reset line on the SMC… I disconnected it and it started working for a second and gave what I thought could be a correct output…(Outputs seem to reverse every 3 seconds)
It then stopped working and I continued to play with the reset line…
When gnd is connected to reset it outputs all GND (Correct)
When reset line is allowed to “float” It sometimes works and sometimes doesnt (Different results all the time)
When reset is connected to 5v high output from RB0 on 16f628 i get the same results that I posted before which seem to be erroneous

I will take out all my code and just send those bytes, jan. I will post back after testing and tell results and my entire code.
Thanks jan

Test results:
Motor0
GP1: GND
GP2: +5v

Motor1
GP0: +5v
GP5: GND

Seems everything is working fine. Makes me sad to think it must be my code after all the checking I’ve gone through…
Sorry for the problem jan.

Problem code:

;***********************************************;
;	First PIC program			;
;	   					;
;	Implented a Motor Controller		;
;						;
;						;
;						;
;************************************************
    					;Testing and Simulation
	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	__config 0x3D18			;sets the configuration settings 
					;(oscillator type etc.)

;****** Variables **************************************************************


	TEMPW	EQU     H'20'   	;This is the start of the General Registers.

	Motor0	EQU	H'21'		; Motor0 speed
	Motor1	EQU	H'22'		; Motor1 speed
	rev0	EQU	H'23'		; Reverse flag for Motor0
	rev1	EQU	H'24'		; Reverse flag for Motor1


	count1	EQU	H'25'		; Delay Variables.
	counta	EQU	H'26'
	countb	EQU	H'27'		


	org	0x0000			;org sets the origin, 0x0000
	goto 	main			;this is where the program starts running	



	org	0x0004			;org sets the origin, 0x0004
	goto	IntH			;this is where interrupts are vectored	



main

;
; -------------------------------- 
; set ANALOG/DIGITAL INPUTS PORT A 
; -------------------------------- 
; 
	movlw	0x07
	movwf	CMCON			;turn comparators off



; 
; ---------------- 
; INITIALIZE PORTS 
; ---------------- 
; 

        movlw b'00000000'       ; set up portA 
        movwf PORTA 

        movlw b'00000100'       ; RB2(TX)=1 others are 0 
        movwf PORTB 


   	bsf 	STATUS,		RP0	;set   RP0
	bcf 	STATUS,		RP1	;clear RP1	This selects Bank 1

   	movlw 	b'00000000'		;Set all ports to output on PortA
   	movwf 	TRISA
   	movlw 	b'00000010'		;Set all ports output, RB1(RX)=1 
	movwf	TRISB


	bcf	INTCON, 	GIE	;Global Interrupt Disable   (clear)
	bcf	INTCON, 	INTE	;External Interrupt Disable (clear)
	bcf	INTCON, 	INTF	;External Intterupt flag



; Serial transmit setup

	movlw	d'25'
	movwf	SPBRG			;Set the baud rate.


	bsf	TXSTA,		BRGH	;high speed baud rate mode
   	bcf	TXSTA,		TX9	;8bit transmission
	bcf	TXSTA,		SYNC	;Asynchro mode   idk?

	bcf	PIE1,		TXIE	;Interupts disabled


   	bcf 	STATUS,		RP0	;clear RP0   This will select bank 0


   	bsf	RCSTA,		SPEN	;Serial Port Enable. Do I need this? sure..
	bcf	RCSTA,		RX9	;8bit receive
	bcf	RCSTA,		CREN	;Continous Receive disable


   	bsf 	STATUS,		RP0	;set   RP0   This selects Bank 1
	bsf	TXSTA,		TXEN	;Transmit Enable bit
   	bcf 	STATUS,		RP0	;clear RP0   This selects Bank 0


;	movlw	0x00
;	movwf	PORTA
;	movwf	PORTB


	bcf 	PORTB,		0	; Set Reset line Low
	call 	Delay			; Let motor controller initialize

	bsf 	PORTB,		0	; Set Reset line high
	call 	Delay			; Let motor controller initialize
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay



Loop	
;	movlw	0xff
;	movwf	PORTA

	bcf 	PORTB,	5	; Turn off Reverse light
	call 	Forward		; Update the motors
	bsf 	PORTB,	4	; Set forward light

	call 	Delay		; Delay for 3 seconds
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay

	bcf 	PORTB,	4	; Turn off forward light
	call 	Reverse		; Update the motors
	bsf 	PORTB,	5	; Set Reverse light

	call 	Delay		; Delay for 3 seconds
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay
	call 	Delay


	goto	Loop			;go back and do it again




Forward
					;Go forward

	movlw 	0x00			;Set M0
 	movwf 	rev0

	movlw 	b'01111111'		;Set the speed for M0  (75% speed)  01011111
   	movwf 	Motor0


	movlw 	0x00			;Set M1
 	movwf 	rev1

	movlw 	b'01111111'		;Set the speed for M1  (75% speed)  01011111
   	movwf 	Motor1

	call 	UpdateMotors		; Update the motor speeds if needed
	return

Reverse
					;Go reverse

	movlw 	0x01			;Set M0
 	movwf 	rev0

	movlw 	b'01011111'		;Set the speed for M0  (75% speed)
   	movwf 	Motor0


	movlw 	0x01			;Set M1
 	movwf 	rev1

	movlw 	b'01011111'		;Set the speed for M1  (75% speed)
   	movwf 	Motor1


	call 	UpdateMotors		; Update the motor speeds if needed
	return

Left
					;Rotate Left

	movlw 	0x01			;Set M0
 	movwf 	rev0

	movlw 	b'00111111'		;Set the speed for M0  (50% speed)
   	movwf 	Motor0


	movlw 	0x00			;Set M1
 	movwf 	rev1

	movlw 	b'00111111'		;Set the speed for M1  (50% speed)
   	movwf 	Motor1


	call 	UpdateMotors		; Update the motor speeds if needed
	return

Right
					;Rotate Right

	movlw 	0x00			;Set M0
 	movwf 	rev0

	movlw 	b'00111111'		;Set the speed for M0  (50% speed)
   	movwf 	Motor0


	movlw 	0x01			;Set M1
 	movwf 	rev1

	movlw 	b'00111111'		;Set the speed for M1  (50% speed)
   	movwf 	Motor1


	call 	UpdateMotors		; Update the motor speeds if needed
	return

Stop
					;Rotate Right

	movlw 	0x00			;Set M0
 	movwf 	rev0

	movlw 	b'00000000'		;Set the speed for M0  (0% speed)
   	movwf 	Motor0


	movlw 	0x00			;Set M1
 	movwf 	rev1

	movlw 	b'00000000'		;Set the speed for M1  (0% speed)
   	movwf 	Motor1


	call 	UpdateMotors		; Update the motor speeds if needed
	return
	


;Serial transmit to motor controller IC

UpdateMotors				;Check to see if we want the speed changed If so Change it

updm0


	call	SerStart
;	call	SerChk			; No longer needed after serial startup
	movlw	b'00000001'
	subwf   rev0,0
	movwf	TXREG
	call	SerChk
	movfw	Motor0
	movwf	TXREG
	call	SerChk

updm1

	call	SerStart
;	call	SerChk			; No longer needed after serial startup
	movlw	b'00000011'
	subwf   rev1,0
	movwf	TXREG
	call	SerChk
	movfw	Motor1
	movwf	TXREG
	call	SerChk

	return


SerStart
	call 	SerChk
	movlw	0x80
	movwf	TXREG
	call	SerChk
	movlw	0x00
	movwf	TXREG	
	call	SerChk
	return

SerChk
	btfss 	PIR1,		TXIF	;Test if the data has been sent from buffer
	goto	$-1			;Does this work?
	return






; Delay code

Delay
	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	return



;----Our Interrupt Handler will go here.----;

IntH
	movwf	TEMPW

	nop	
	nop
	nop
	nop

	bcf	INTCON,		INTF	;Lets set thing back..
	movfw	TEMPW              	;Restore w
	RETFIE
	




	end
      

Also, what I’m trying to do with the subwf is change the 0bit of the motor number byte so i can use “rev0” and “rev1” to control forward and reverse.
0x00 for forward…
0x01 for reverse…

Anything wrong with this method?

I think I see you putting 0 in revx and then subtracting 1, which would give you 0xFF, which is not at all what you want (I might not be remembering what gets subtracted from what correctly, though). In any case, you should use bit manipulation commands for manipulating bits. You can do it with explicit bit instructions (bsf, bcf) or by ANDing and ORing with the right bytes (or with 1 to set, AND with 0 to clear).

In this case, though, it might be easiest to just make four constants for forward and back of your two motors. Our BASIC Stamp example shows how to do this, and you should get the general idea for how to adapt it to your assembly program.

- Jan

Thanks so much jan! I have everything working now…
I have a few questions tho…
What is with the terms:
Vcc
Vss
Vdd
they all seem to mean different things on different diagrams.
I’m used to the “-” moving towards "+"
and not the surplus(+) of electrons moving to the (-)
??
so Vss(source?) would be negative(also known as GND)?

This seems to work for some diagrams… but the one for the
L298 has a GND and a Vss which makes it obvious which is which…
Any input as to how i can not get confused and have to focus so hard on figuring out which is which?

Also, can I parallel 1 output pin with 3 reset pins?
(1 reset for SMC and 2 enable pins for L298)?
Is this bad wiring?

Everything seemed like it would work… I used pins RB4 and RB5 for the enable pins of the H-bridge…
After testing i found out I was getting a weird voltage across the motor0 and motor1 outputs from the L298.
I forgot the current sensing resistors and they were not connected to ground.
I fixed and then everything seem to work fine. I connected a load to the Hbridge outputs and nothing…
The motors i’m trying to run are from a RC car that used a battery pack of 9v and 1A.
I’m using a seperate powersupply for logic and motor control.
a 9v battery through regulator for logic
and a 6v-4A battery for the L298 source
Outputs are correct with no load, but with load connected it shows no voltage across the poles.
I have no protection diodes and I do not have the recommened 100uf capacitor across Vss and GND

The history of naming conventions and how electricity works are big topics I don’t want to get into, but here are some quick answers. Current is usually viewed as going + to -, even if the electrons are going the other way. It generally doesn’t matter too much as long as you’re consistent within your calculations (including being happy with thinking of current one way as the same as a negative current the other way), but for communicating with others, it’s good to stick with conventions.

Various circuits and ICs have different voltages on them, so ‘+’ and ‘-’ doesn’t necessarily cut it, and GND isn’t necessarily ‘-’ if ‘-’ is a negative voltage (you can also have various grounds). Vcc is comes from BJT-based circuits; Vdd comes from MOSFET-based circuits. Neither label gives you an actual voltage: for example, Vdd might need to be 5 V or 3.3 V, depending on the part. So, you have to look at the datasheets, and they will tell you what each pin means. Generally, Vcc and Vdd are the positive supplies, and Vss is the negative supply or ground.

Battery packs generally don’t have current ratings. They have maximum currents, but the numbers you usually see are for capacity, measure in Ah (amp-hours) instead of just A. So your battery pack is probably a 9 V, 1 Ah battery pack, which means that it should be able to deliver 1A for about an hour. If your RC car drained that battery in 6 minutes, it was drawing 10 A, which would be well past the limit of the L298. So, you might try a smaller motor to see if your circuit is working.

- Jan