Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM asm code for 16F84A

Status
Not open for further replies.
Is it posible the microcontroler to be burned out ? and if it is will the programer indicate this ? I use PICkit ver 2.55 programer. Is there some way to check the condition of crystal and condensers ?
 

Hi,

V 2.55 thats rather old, you want to download the latest version 2.61, allows you to program and debug many more chips.
You can also program direct from MPLAB, use the Programmer Menu.

The programmer can read,erase and write to the memory arrays of the chip, doubt it could help test anything else.

You want to start with your +5v supply, is that good ?, if not use 4.5v of batteries for a test.

Disconnect your resistors to the transistors, program up a simple led flasher to test the chip and see if that works.
If ok then transfer the led to the ports used by the resistors and see if they work ok.
If ok, suspect the transistors, do they get hot, are they on a heatsink ?
Any idea how much current your motor takes at full speed / 12v.
 

Hi,

V 2.55 thats rather old, you want to download the latest version 2.61, allows you to program and debug many more chips.
You can also program direct from MPLAB, use the Programmer Menu.

The programmer can read,erase and write to the memory arrays of the chip, doubt it could help test anything else.

You want to start with your +5v supply, is that good ?, if not use 4.5v of batteries for a test.

Disconnect your resistors to the transistors, program up a simple led flasher to test the chip and see if that works.
If ok then transfer the led to the ports used by the resistors and see if they work ok.
If ok, suspect the transistors, do they get hot, are they on a heatsink ?
Any idea how much current your motor takes at full speed / 12v.

1. The supply I using is USB adapter for mobile phone (220V => 5V) but I already tried to use my laptop's USB. With multimeter I measured it and it is OK.
2. I disconnected the resistors and tried with simple program but nothing happеnеd again
3. I dont know what is the current which the motor takes but I using old computer supplay for the 12V (to motor)

I think the problem is in the crystal or may be in C2/C3 . First time when evrything stoped work I saw the cable from supply +5V was freaked out ... then I solder it but nothing happened .... The question is - is it posible this cable to burn out something in the board if with touch ?( because it is posible to move around before I saw it is fraked out)
 
Last edited:

Hi,

Sounds like you need some better hardware !! ;-)

Doubt that the crystal will be damaged, more likely the connections to it. The crystal and caps should be as close to the Pic as possible, no long leads.

Your relay also needs a 1N4001/6 type diode across the coil so stop interference.
https://romux.com/tutorials/pic-tutorial/relay


This link might be of interest should you want to use a lcd with the 84A
 

OK , the hardware is ready now .... but the problem with the program is still here .... I think I need more information about how the counter works in assembler because I was thinking it is like in Java and C++ (just define and use) but it is not ..... can someone help me with this because I googled but I don't understand it ..... can someone explain it like if idiot must understand it ?I am not a idiot but close :) wp100 ? ( you are good in that :D I know because I understands evrything you said .... or may be most of what you said )
 

Hi,

What exactly is the probelm ? is it with your own code or one of the examples I posted ?

Can you post the assembler code of what you have programmed so I can simulate it.

( did you find out what component you burnt out ,if any, or have you just used all new parts ? )
 

I used new parts (twice because of problems with soldering but nvm). The problem is :
what must happen:rotating forward at 100% speed ; pause ; rotating forward at 50% speed; pause ; rotating backward at 100% speed ; pause ; rotating backward at 50% speed;pause ; start from the begining.
what really happen:rotating forward at 100% speed ; pause ; rotating forward at 50% speed; pause ; rotating backward at 100% speed ; pause ; rotating forward at 50% speed to infinity;

The code:
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		d'100'


		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'30'
		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'70'
		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'90'		; 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'90'		; 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

PS: Which program you are using for simulation ? Is it difficult to use this program (for beginners)?
 

Hi,

Will have a look at your code a bit later this evening, I'm on GMT.

Did you try that 10 second code I did in post entry #13 ?

It outputs pwm on pins RB0 and RB1, as in your first code sample in post entry #9, but it now also uses timer0 to count down 10 seconds run time.
 

yep I tried the code from your post (#13) but nothing happens .... should I need to change something in it ?
But ultimately the algorithm which I was made working almost perfect (4/5 of the target) so I am not sure but I thing it will be batter to fix it instead of to change it . I am wrong ? :roll: And again I want to say thx a lot .....dude ....( you never told me your name) ....
 
Last edited:

Hi,
When you build the code, as shown in #27, it does build ok, but it does actually give an error - Invalid Ram.
After it builds, go back and look at the Output Report.
You do not need to specify any of the other system registers like W, they are provided by the Include file.

I have corrected the code so it builds without error.

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

Counter equ		0x0c
duty	equ		0x0d		; length of duty cycle
temp	equ		0x0e		; length of duty cycle
cou	equ		0x0f





        		ORG 	H'0000'
        		goto 	start

start			movlw 	d'100'
			movwf	cou

				bsf 	STATUS,RP0
        		movlw 	B'11010111'

The reason you code seems to stick is that it gets stuck in a loop on the 50% routines.
It never reaches 'cou' to decrement it.

Have a look at how I have used Timer0 in that 50% code of yours, it works in simulation fine using the same layout as your current code runs on.


Code:
pwmb50f			nop 
        		nop
        		nop
        		decfsz	temp
        		goto	pwmb50f
        		bcf	INTCON,T0IF ;; YOU CLEAR THE TIMER FLAG HERE  
        		btfss 	INTCON,T0IF   ;;NEXT INSTRUCTION YOU TEST IF ITS SET, IT WILL NOT BE , SO IT GOES BACK TO  pwm50f
        		goto	pwm50f
        		decfsz	cou
        		clrf	TMR0
        		return
 

I am get up now and I must go ....I will see this better after work ... thx
 

get worse ... :-( the motor starts to rotate forward 100% speed; pause ; rotate forward 50% speed to infinity

---------- Post added at 12:49 ---------- Previous post was at 11:45 ----------

Everything is fuc*ed. I think I am going to give up. It is too difficult for me ..... after I tried the code from the preview post (and I saw it is not working) , I programmed my last code (post #27 I think) and it not working anymore .... when I start my device the motor turns on forward at 100% speed then pause then forward 50% to infinity ......... Where is the logic to do that with the old program (which was working before) ??? I am too stupid to understand and explain this to myself 8-O:|:-( How it was working before and now the same code doesn't work ?
 

Hi,

Its very easy to get things all mixed up when starting out.

Having to learn the code, Mplab, the Programmer and building the circuit, its so easy to make mistakes, we have all got in a tangle at some stage, where everything seems to go wrong.

Leave things for a day or so and come back with a fresh mind and its surprising how things then staart to work ok !

I would stongly suggest you start off again doing a tutorial on a flashing led so you steadily build up your experience.
The WInPicProg tutorial is a good start.

That tutorial also does hardware PWM using the 16F876 chip, that is so much easier to use and you can do countless different speeds.

Can you easily get hold of a 16F876/A chip ? Any of the 873/4/6/7 A chips will work fine with his code and 876 and 877 chips are a common choice in many other online projects.

If they are not easy to get I could post you over a programmed up 873 chip to get you going.
 

YESSSSSSSS :) I MADE IT :-D..... TOGETHER WE MADE IT :p .

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

w		EQU		0
f		EQU 	1
portb	equ		0x06		; port b equate
Counter EQU		0x0c
duty	equ		0x0d		; length of duty cycle
temp	equ		0x0e		; length of duty cycle
cou		equ		0x0f


		ORG 	H'0000'
		goto 	start

start	movlw	d'100'
		movwf	cou
		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'70'
		movwf	Counter
		clrf	TMR0
againA	bcf		INTCON,T0IF
loopA	btfss 	INTCON,T0IF
		goto	loopA
		decfsz	Counter,f
		goto	againA
		return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;pwm 50% speed
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pwm50	movlw	d'0'
		movwf	portb
		movlw	d'90'		
		movwf	duty
		movf	duty,w
		movwf	temp
		bsf		portb,0
		bsf		portb,1
pwma50	nop
		nop
		nop
		decfsz	temp	
		goto	pwma50
		movlw	d'255'
		movwf	temp
		movf	duty,w
		subwf	temp,f
		bcf		portb,0
		bcf		portb,1		

pwmb50	nop 
		nop
		nop
		decfsz	temp	;temp = temp-1 . temp=0 ?
		goto	pwmb50	;НЕ - изпъни отново
						;ДА - прескочи "goto pwmb50f"
		
		btfss 	INTCON,T0IF  ;бит T0IF=1???
		goto	pwm50	;НЕ - върни се в началото на подпрограмата
		decfsz	cou		;ДА - намали cou с 1. cou=0 ?
		goto	t0clr	;НЕ - върни се в началото на подпрограмата
		return			;ДА - върни се към главната програма
		
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;t0clr - нулиране на бит T0IF на TMR0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
t0clr	bcf		INTCON,T0IF
		goto	pwm50 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;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

		movlw	d'100'
		movwf	cou
		clrf	TMR0
		bcf		INTCON,T0IF 	
		call	pwm50	
		call	WaitP

		call	pwm100b
		call	WaitP

		movlw	d'100'
		movwf	cou
		clrf	TMR0
		bcf		INTCON,T0IF 
		bsf		portb,2	
		call	pwm50
		bcf		portb,2
		call	WaitP

		goto	main
	
		END

Soon I will start with new project .... something more easy .... may be something with LEDs :) ... cya
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top