PWM asm code for 16F84A

Status
Not open for further replies.

moschino891129

Junior Member level 1
Joined
May 16, 2012
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bulgaria
Activity points
1,451
First I want to say sorry for my "English"
So now I can continue with HI ALL
I am very new in microcontrollers and I have only the basic knowledge for electronics ... I hope to start my adventure with this project -
https://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/
but I have a problem with the software part of challenge... in the tutorial the author says "It's not rocket science" about the code, but for me IT LOOKS LIKE ROCKET SCIENCE (I mean the asembler code for this function ).
So anyway , can you people help me with converting the code to asembler usable for pic16f84a and if it's posible to be with more coment (cuz I want to understand what evrything means)?

I tried to write the code using combination of two codes - first code which turns ON and OFF LED for some delay and second code with PWM which dims the LED , but I faild ... evrything I made was to dim the LED but I can't escape from the pwm loop of my code ...

May be this will be very funny for you people but I will share my bullshits
there is :
Code:
		list	p=16f84
		radix	hex
		#include	<p16F84A.inc>
		__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

w		EQU		0
f		EQU 	1
Counter EQU		H'0C'
portb	equ	0x06		; port b equate
duty	equ	0x0c		; length of duty cycle
temp	equ	0x0d		; length of duty cycle
c		equ	0

start	bsf 	STATUS,RP0
		movlw 	B'11010111'
		movwf	OPTION_REG
		bcf		STATUS,RP0
		clrf	PORTB
		bsf		STATUS,RP0
		movlw	B'11111110'
		movwf	TRISB
		bcf 	STATUS,RP0
		goto 	main


ACTA	        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'10'		; Duty cycle length
		movwf	duty
b0loop	movf	duty,w
		movwf	temp
		bsf		portb,0
pwma	        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
		decfsz	temp
		goto	pwmb
		goto	rstrt
		return


WaitA	        movlw	D'30'
		movwf	Counter
		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA 	btfss 	INTCON,T0IF
		goto	loopA
		decfsz	Counter,f
		goto	againA
		return



ACTB	        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
rstrtB	        movlw	d'0'
		movwf	portb
		movlw	d'200'		; Duty cycle length
		movwf	duty
b0loopB	movf	duty,w
		movwf	temp
		bsf		portb,0
pwmaB	nop
		nop
		nop
		decfsz	temp	
		goto	pwma
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
pwmbB	nop
		nop
		nop
		decfsz	temp
		goto	pwmbB
		goto	rstrtB
		return


WaitP	        movlw	D'30'
		movwf	Counter
		clrf	TMR0
againP	bcf		INTCON,T0IF
loopP	        btfss 	INTCON,T0IF
		goto	loopP
		decfsz	Counter,f
		goto	againP
		return


main
		call	ACTA
		call	WaitA
		call	WaitP
		call 	ACTB
		call	WaitA
		call 	WaitP
		goto	main
		END
 
Last edited by a moderator:

Hi,

Welcome to the forum.

The Indestructable project uses the Arduino hardware which is programmed in C++.

You want to do the same on a Pic chip in Assembler, ok, but my suggestion would be to use a tutorial and start from the beginning.

This site will guide you though the basic hardware and software of flashing a led and things like PWM.
http://www.winpicprog.co.uk/pic_tutorial.htm

One important point, there are two types of PWM program code, hardware PWM and software PWM.
Many modern Pic chips have an inbuilt PWM circuit which makes coding very easy, this is know as the hardwre PWM.
Earlier chips like the16F84A do not have any PWM hardware built in, so it has to use a lot of program code to do the same job, so its called a software PWM, which is best to avoid.

Would suggest you use a more modern chip like a pic16f876A/877A as suggested in that tutorial.


If you get stuck, post your problem here, plenty of folk to help you get going
 

Thx for information wp100, but I already googled (may be more than 5 hours) before I post thread here and I learn many about PWM. I bought two books for pic16f84 and this is the reason of my choise (in many forums I read "the perfect microcontroller for beginners is 16f84a") but the problem is that in this books haven't information about software pwm.
The other reason of my choise (pic16f84a) is that - next year in HS we will work with 16f84 and I want to learn more now ... (cuz I am studing and working in same time - something like remote school )

So anyway is there someone who can help me with the code ?

PS: this is the link where I found best info about software PWM - **broken link removed**
 
Last edited:

You will find in all of the tutorials, including the one cited by wp100, that one of the very first projects is to flash an LED. That is PWM. A pin is turned on, delay, turned off, delay, repeat forever. The ratio of "on time" to total cycle time (on + off) is the duty cycle. One second divided by the cycle time is frequency.

For your choice of device, you may need to find a tutorial written for the 16F84A. Nigel Goodwin's (as cited above) is written for the newer 16F628. If all you need is something written for the 16F84A, let us know. If there is something else about PWM that you still are not sure of, please expand on that.

John
 

Hi,

The 16F84A is a very old chip, though there are still many web based projects for it.
If you have got to do a course based on it, then yes, think for now you will have to stick with it.

Which books have you got, do they not guide you through starting up and flashing a led ?

Have looked at the code you posted with MPlab v8.8 and made a couple of minor corrections to it.
As you can see from the screen shot it seems to produce a stream of signals.

However I don't have the time do go though all that code, understand it and add comments to each step for you.

Perhaps try going thought it in stages yourself, if stuck ,then post that bit of code for some help.

Code:
        		list	p=16f84A
        		radix	hex
        		#include	<p16F84A.inc>
        		__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

w		EQU		0
f		EQU 	1
Counter EQU		H'0C'
portb	equ	0x06		; port b equate
duty	equ	0x0c		; length of duty cycle
temp	equ	0x0d		; length of duty cycle
c		equ	0

start			bsf 	STATUS,RP0
        		movlw 	B'11010111'
        		movwf	OPTION_REG
        		bcf		STATUS,RP0
        		clrf	PORTB
        		bsf		STATUS,RP0
        		movlw	B'11111110'
        		movwf	TRISB
        		bcf 	STATUS,RP0
        		goto 	main

ACTA	       nop
				banksel TRISB
			    movlw	      0x00		; load W with 0x00 make port B output
        		movwf	TRISB		; copy W tristate to port B outputs
				banksel PORTB
        		movlw	0x00		; fill w with zeroes
        		movwf	portb		; set port b outputs to low
rstrt       	movlw	d'0'
        		movwf	portb
        		movlw	d'10'		; Duty cycle length
        		movwf	duty
b0loop	movf	duty,w
        		movwf	temp
        		bsf		portb,0
pwma	        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
        		decfsz	temp
        		goto	pwmb
        		goto	rstrt
        		return


WaitA	        movlw	D'30'
        		movwf	Counter
        		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA 	btfss 	INTCON,T0IF
        		goto	loopA
        		decfsz	Counter,f
        		goto	againA
        		return

ACTB			nop
		       banksel TRISB
				movlw	0x00		; load W with 0x00 make port B output
        		movwf	TRISB		; copy W tristate to port B outputs
				BANKSEL  PORTB
        		movlw	0x00		; fill w with zeroes
        		movwf	portb		; set port b outputs to low
rstrtB	        movlw	d'0'
        		movwf	portb
        		movlw	d'200'		; Duty cycle length
        		movwf	duty
b0loopB	movf	duty,w
        		movwf	temp
        		bsf		portb,0
pwmaB	nop
        		nop
        		nop
        		decfsz	temp	
        		goto	pwma
        		movlw	d'255'
        		movwf	temp
        		movf	duty,w
        		subwf	temp,f
        		bcf		portb,0
pwmbB	nop
        		nop
        		nop
        		decfsz	temp
        		goto	pwmbB
        		goto	rstrtB
        		return


WaitP	        movlw	D'30'
        		movwf	Counter
        		clrf	TMR0
againP	bcf		INTCON,T0IF
loopP	        btfss 	INTCON,T0IF
        		goto	loopP
        		decfsz	Counter,f
        		goto	againP
        		return


main
        		call	ACTA
        		call	WaitA
        		call	WaitP
        		call 	ACTB
        		call	WaitA
        		call 	WaitP
        		goto	main
        		END
 

Attachments

  • ScreenShot001.jpg
    70 KB · Views: 135


Yes jpanhalt - all I need is something written for the 16f84a. I already do PWM effect on my LED with the code from here:
**broken link removed**
but I don't know how to duplicate the code from the link in second subprogram (with other values) and how to switch between this subprograms.

I think my english is too bad to understand me so this is what I want to do:

Code:
main     call    PWM25 ; 25% pwm for 5 seconds
         call    STOP   ;  stop for 1 second
         call    PWM50 ; 50% pwm for 5 seconds
         call    STOP 
         call    PWM100
         call    STOP
         goto    main     ; repeat forever
 

I didn't see in the listing the following:

Code:
	ORG     0x000             ; processor reset vector
  	goto    main              ; go to beginning of program

That tells the processor where to start. Generally, I follow the "book" when programming in Assembly and use the project wizard provided by Microchip. That includes implicitly a template for the code. Yes, you may end up deleting most of what's included in that template, but it is a good checklist so nothing is left out.

I have attached a text file of the template for the 16F84A. Just copy it to MPLAB and change the extension to .asm.

John
 

Attachments

  • 16F84ATEMP.txt
    3.7 KB · Views: 136

Sorry, we cross posted.

With reference to your post #6, you are calling subroutines that are not included in your original post. Has the project evolved?

There are several ways to approach doing what you seem to want to do, that is, three PWM settings to run for fixed times and repeated forever.

A straight-forward, brute-force method would be to simply write each PWM as a subroutine as you have done, then set up a counter to make each subroutine run the number of times needed to get the period for each PWM that you want. I suggest setting up the delays that will be needed as separate subroutines. Piclist has a delay code generator that you may find useful ( ).

In other words, PWM25 needs to be written. Do you have an example of your effort to do that? What frequency have you set the MCU at?

I call that brute force. More refined methods may use the MCU timer to set interrupts, a generic PWM subroutine in which you insert variables, and so forth. I assume you have not gotten into using the timer and interrupts.

John
 

I am almost ready guys... I made my DC motor to rotate forward , then after pause backward ... I am very happy because I see progress :-D
I tried the program with PWM and it works
And now all I need is help to merge two programs ..... pls help me.


I want to make this working "PWM program" :


Code:
	list	p=16f84
	radix	hex
	#include	<p16F84A.inc>
	__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC


;----------------------------------------------------------------------

portb	equ	0x06		; port b equate
duty	equ	0x0c		; length of duty cycle
temp	equ	0x0d		; length of duty cycle
lenght	set	d'157'
;---------------------------------------------------------------------

c		equ	0		; status bit to check after subtraction

;---------------------------------------------------------------------

		org	0x000

start	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	lenght		; Duty cycle length
		movwf	duty
b0loop	movf	duty,w
		movwf	temp
		bsf		portb,0
		bsf		portb,1
pwma	nop
		nop
		nop
		decfsz	temp	
		goto	pwma
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
		bcf		portb,1		

pwmb	nop
		nop
		nop
		decfsz	temp
		goto	pwmb
		goto	rstrt

		
		END

subroutine of this working program

Code:
		list 		p=16F84A
		#include	<p16F84A.inc>
		__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

w		EQU		0
f		EQU 	1
Counter EQU		H'0C'

		ORG 	H'0000'
		goto 	start

start	bsf 	STATUS,RP0
		movlw 	B'11010111'
		movwf	OPTION_REG
		bcf		STATUS,RP0
		clrf	PORTB
		bsf		STATUS,RP0
		movlw	B'11111000'
		movwf	TRISB
		bcf 	STATUS,RP0
		goto 	main


WaitA	movlw	D'150'
		movwf	Counter
		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA	btfss 	INTCON,T0IF
		goto	loopA
		decfsz	Counter,f
		goto	againA
		return

WaitP	movlw	D'5'
		movwf	Counter
		clrf	TMR0
againP	bcf		INTCON,T0IF
loopP	btfss 	INTCON,T0IF
		goto	loopP
		decfsz	Counter,f
		goto	againP
		return


main	bsf		PORTB,0
		bsf		PORTB,1
		bsf		PORTB,2
		call	WaitA
		bcf		PORTB,0
		bcf		PORTB,1
		bcf		PORTB,2
		call	WaitP
	
		bsf		PORTB,0
		bsf		PORTB,1
		call	WaitA
		bcf		PORTB,0
		bcf		PORTB,1
		call	WaitP
		goto	main
		END

but I fail again and again and again .... I tried to make something like counter in "pwm program" which one to escape from "PWM loop" but I don't know how to do that working. I also tried to make variable (with the lenght of duty cycle) in "pwm program" which one to be increased when counter goes to zero(counter must decrease every circle) .... there is my fail :
Code:
	list	p=16f84
	radix	hex
	#include	<p16F84A.inc>
	__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC


;----------------------------------------------------------------------

portb	equ	0x06		; port b equate
duty	equ	0x0c		; length of duty cycle
temp	equ	0x0d		; length of duty cycle
lenght	set	d'10'
cou		set d'100'
;---------------------------------------------------------------------

c		equ	0		; status bit to check after subtraction

;---------------------------------------------------------------------

		org	0x000

start	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	lenght		; Duty cycle length
		movwf	duty
b0loop	movf	duty,w
		movwf	temp
		bsf		portb,0
		bsf		portb,1
pwma	nop
		nop
		nop
		decfsz	temp	
		goto	pwma
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
		bcf		portb,1		

pwmb	nop
		nop

		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA	btfss 	INTCON,T0IF
		goto	loopA
cou		set		cou-1
		if		cou==0
lenght	set		lenght+10
		else
		nop
		decfsz	temp
		goto	pwmb
		goto	rstrt

		
		END

PLS HELP ME TO FINISH THIS
 
Last edited:

Hi,

You need to specify what crystal speed you are using.

It also helps if you add a lot more " ;comments " to your code so we can follow your logic easier.

Example 1 works fine and produces a train of pulses.

Example 2 just seems to go high every 10 seconds, is that intended ?
The hardware timers can be used for delays, but its often handier to use a software delay.
**broken link removed**

Example 3 just gets stuck in a loop, although seeming to build ok if you look at the Ouput Build Report you can see it shows your directives are incomplete. Expected (ENDIF)
 

Attachments

  • ScreenShot001.jpg
    64.8 KB · Views: 125

I think I am confused. There are two options :
1-st I am too stuped for this
2-nd I can't explain (in English) what I want to do ...

The crystal is 6 MHz but this is not important because I don't need exact timing.

OK I will try again with simple words and I hope you'll understand me....(it is more likely to confuse you even more but I will try)

Again sorry for my english but it's hard for me (I use google translate often for many words)

In the first code of my post #9 I showed you PWM program which I tested and it's working.(make my motor to rotate in 50% power)
This program is closed cycle which starts at "rstrt" and stops in " goto rstrt". This cycle makes the PWM.

The second program is that I was made. In the "main" I am simply turns pins 0,1 and 2 (PORT B) in to "HIGH".
This makes:
1. the led (connected to RB0) to shine
2. turns motor ON (high level on RB1)
3. sets the motor direction (high level on RB2)

then I "call" subroutine WaitA which makes 9-10 seconds delay (this measured the time of led and motor working)

after that I turning OFF the led and motor and call WaitP which makes 1 second delay (pause) and then I turning led and motor ON again but this time RB2 is on low level and the motor change his direction ....and this repeats forever


What I want to do is to embed the PWM program in my program, and to make my motor to rotate in one directions then to stop and change direction or something like that BUT on 50% power . The final code in "main" I suppose must be something like that :
Code:
main	        call    PWM                 ;subroutine which turning on led and motor at 50%pwm on RB0(led),RB1(motor)
		call	WaitA                ; subroutine which shows how much time PWM subroutine will work
		bcf		PORTB,0    ;turn off the led
		bcf		PORTB,1    ;turn off the motor
		bcf		PORTB,2    ;set the direction
		call	WaitP                ;small pause
	
		bsf		PORTB,0     ;turn the led ON in 100% power
		bsf		PORTB,1     ;turn the motor ON in 100% power
		call	WaitA
		bcf		PORTB,0
		bcf		PORTB,1
		call	WaitP
		goto	main

or something like that .... I realy hope you understand me after all :roll: . PLS HELP ME I STUCK IN THIS CODE :???::-(8-O
 
Last edited:

I think I am confused. There are two options :
1-st I am too stuped for this
2-nd I can't explain (in English) what I want to do ...

Hi,

1. No you are not - at least you are having a good go at it yourself, many do not even try a line of code themselves.

2. Your English is coming though fine.

Your problem really revolves around the Software PWM you are using because the old 84A chip does not have a hardware PWM built in which makes things so much easier.

Most of what you are trying to do is easy to program, the difficult bit is running the PWM for a specifed time.

The way I would do it is with Timer0, this is an independant bit of hardware that runs as a simple Counter/Timer, while allowing your main program code to carry on running.
Timer0 only runs for a short while , not for 10 minutes, each time it complete its count it Sets a 'Flag' to say its finished.

So just before you call your PWM routine, you set up Timer0 and its Prescaler to give the maximum time with your 6 meg crystal and start it running.
You also set up a register to count the number times of Timer0 has to run to give your 10 mins. - lets call it Count10 and store 0x64 in it, though you will have to work out the exact value for it.


You enter your PWM routine, when it gets to the end of the first loop, intead of going back the the beginning, it checks if Timer0 Interrupt Flag is set to say its timed out.
btfss OPTION_REG,T0IF
If it has not, then goto to the start of the loop again

If it is set on, then you reduce COUNT10 by 1, and see if it is Zero, that is 10 mins is up.
DECFSZ COUNT10,F
If it is Zero then you end the PWM routine.
If its not Zero then you must now Clear Timer0 and reset the Flag so it starts counting again, then you go back to the start of the loop again.

It may seem like a lot of instructions but its so fast it should not affect your PWM timings.

Hope thats clear for you, if not come on back - either way let us know how you get on, if I cannot help someone else surely will.
 
Hi,

In case you are finding that code difficult I have done an example of Timer0 with a 10 second delay.
It needs to be integrated into your PWM code but will let you try it yourself.
 

Attachments

  • timer0.rar
    47.3 KB · Views: 125
Dear wp100 your post #12 really helped me..... I make succeed last night :razz:. I see that you make tmr0 code for me (#13) and thx for it .
Now with this code I made my motor to rotate in forward directions at 100% then after pause forward at 50% , pause , backward 100%,pause and backward 50%....
Code:
		list 		p=16F84A
		#include	<p16F84A.inc>
		__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

w		EQU		0
f		EQU 	1
Counter EQU		H'0C'
c		equ		0
portb	equ		0x06		; port b equate
duty	equ		0x0c		; length of duty cycle
temp	equ		0x0d		; length of duty cycle
cou		set		0x64

		cblock
		d1
		d2
		endc
		ORG 	H'0000'
		goto 	start

start	bsf 	STATUS,RP0
		movlw 	B'11010111'
		movwf	OPTION_REG
		bcf		STATUS,RP0
		clrf	PORTB
		bsf		STATUS,RP0
		movlw	B'11111000'
		movwf	TRISB
		bcf 	STATUS,RP0
		goto 	main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;deley for the pause between subroutines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WaitP	movlw	D'50'
		movwf	Counter
		clrf	TMR0
againP	bcf		INTCON,T0IF
loopP	btfss 	INTCON,T0IF
		goto	loopP
		decfsz	Counter,f
		goto	againP
		return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;delay for the time of Action on pwm100b and pwm100f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WaitA	movlw	D'100'
		movwf	Counter
		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA	btfss 	INTCON,T0IF
		goto	loopA
		decfsz	Counter,f
		goto	againA
		return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;pwm 50% forward
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pwm50f	movlw	d'0'
		movwf	portb
		movlw	d'70'		; Duty cycle length
		movwf	duty
		movf	duty,w
		movwf	temp
		bsf		portb,0
		bsf		portb,1
pwma50f	nop
		nop
		nop
		decfsz	temp	
		goto	pwma50f
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
		bcf		portb,1		

pwmb50f	nop 
		nop
		nop
		decfsz	temp
		goto	pwmb50f
		bcf		INTCON,T0IF
		btfss 	INTCON,T0IF
		goto	pwm50f
		decfsz	cou
		clrf	TMR0
		return
		

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;pwm 50% backward
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pwm50b	movlw	d'0'
		movwf	portb
		movlw	d'70'		; Duty cycle length
		movwf	duty
		movf	duty,w
		movwf	temp
		bsf		portb,0
		bsf		portb,1
		bsf		portb,2
pwma50b	nop
		nop
		nop
		decfsz	temp	
		goto	pwma50b
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
		bcf		portb,1
		bcf		portb,2		

pwmb50b	nop
		nop
		nop
		decfsz	temp
		goto	pwmb50b
		bcf		INTCON,T0IF
		btfss 	INTCON,T0IF
		goto	pwm50b
		decfsz	cou
		clrf	TMR0
		return
		

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;pwm 100% forward
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pwm100f	bsf		portb,0
		bsf		portb,1
		call	WaitA
		bcf		portb,0
		bcf		portb,1		
		return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;pwm 100% backward
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pwm100b	bsf		portb,0
		bsf		portb,1
		bsf		portb,2
		call	WaitA
		bcf		portb,0
		bcf		portb,1
		bcf		portb,2		
		return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main	call	pwm100f
		call	WaitP
		call	pwm50f
		call	WaitP
		call	pwm100b
		call	WaitP
		call	pwm50b		
		call	WaitP
		goto	main
	
		END

BUT ( of corse there is BUT ;-) ) I have a problem with tmr0 because when the motor starts to rotate forward or backward in 50% (with the PWM) my timing starts to s*ck.... I mean once it do it for 5 seconds , once for 10 once for 7 - it's unpredictable. I saw in your code how you SET tmr0 but I think it will never escape from the routine tm0start -> goto tm0start or tm0end -> goto tm0end ...... can you pls look at my code for a while .... may be you will see where my mistake is. I know it is something with my tmr0 but I cant understand what ? THX A LOT AGAIN :roll:
 

I thing I solved the problem .... After "pwm50f" the value of "cou" = 0 , so if I set it to 100 again before "pwm50b" it will works .... I hope so ... but there is other problem ...... something on my board is burned and nothing happends when I turn ON the power suply ..... I will buy new parts monday and will made the schemе again ..... new week - new luck :roll:
 

thx for that dude

Hi,

You have done a lot of coding since my suggestion last night.

Rather than try and change all of your current work I have taken the 50/50 code that worked yesterday and inserted the 10second Timer0 routine into that.

I hope you can see how it works.

Your latest 100% routines now also seem to use Tm0 for delays in creating the pwm pulses.
They will obviously clash with the use of TM0 for the total On time.

You can get round that by using simple software delay subroutines, sample in the code attached - use this calculator for what ever time you need.
**broken link removed**
 

Attachments

  • pwn10.rar
    1.2 KB · Views: 98



Hi,

What has burned out ?

What are you using to interface the Pic to the Motor ?

Can you post a circuit diagram.
 


Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…