Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help in my wierd problem...

Status
Not open for further replies.

ym2k

New Member
Hi all,

I have been using 16f84a to do a cretain project, as 16f84a only got 1k memory, i had problem to continue writing the program due to my program size. I then decided to use 16f648a which can provide me 4k memory to write on. i have type in this line :

movlw d'07'
movwf cmcon ;CMCON=7 set comperators off

To set the comperators features of 16f648a off. Once it is done, i assume is basic I/O function is around the same as 16f84a. I am wrong, hen i try to program and run, my indicators(led&7-segments) give me a totally wrong value everytime i power my chip... why?
 
It's impossible to say without seeing all the program, but I would suggest you're perhaps not setting something up correctly - perhaps relying on the default settings for the 16F84?, which may well be different. In any event, you shouldn't rely on default settings, you should always set everything explicitly.
 
Nigel Goodwin said:
It's impossible to say without seeing all the program, but I would suggest you're perhaps not setting something up correctly - perhaps relying on the default settings for the 16F84?, which may well be different. In any event, you shouldn't rely on default settings, you should always set everything explicitly.

Thanks for that quick reply, i am using mplab to program, i have change all necessary setting to 16f648a:

list p=pic16f648a
include p16f648a.inc
__config _hs_osc & _lvp_off &_wdt_off & _pwrte_on & _cp_off &_boden_on
errorlevel -302 ;Eliminate bank warning

I also select the correct device to compile using mplab. These are all the change i made including the comparator feature, therefore i asume it should work as well as what i can in 16f84a. My code settle at 1024 program memory which is just nice for 16f84a, but i have not finish completing the program. Do i need to use bank switch or somthing to change any program memory bank(if there is any)? I use to switch 16f84a and 16f628a, and never give me any problem. This is the 1st time i face the program length in 16f84a and 1st time using 16f648a, so i really in doubt now....
 
There's no bank switching required in the first 2K of memory, so with a 16F628 it's never a concern :D

With a 648 you have two banks, but as long as you keep under 2K, again you don't need any bank switching.
 
Hm, i really dun know what happn now. I bought 3 16f648a chip and program the same code on 3 of them. I wrote a simple code like this:


Code:
;	Using 20Mhz crystal at 0.2us every cycle.


	list            p=pic16f648a
	include      	p16f648a.inc
	__config _hs_osc & _lvp_off & _wdt_off & _pwrte_off & _cp_off & _boden_off
	errorlevel	-302    ;Eliminate bank warning

;****************  Initial Process  *********************

	org	h'00'
	goto	main
	org	h'04'
	goto	main

main	movlw 	d'07' 
        movwf 	cmcon		;CMCON=7 set comperators off 

	bsf     status,rp0      ;Change to Bank1 
	movlw   b'10100111'     ;Set mode for PORTA
	movwf   trisa           ;Set PORTA pin 0-2 to Input mode
	clrf    trisb           ;Set PORTB to Output mode
	bcf     status,rp0      ;Change to Bank0
	
	bcf 	intcon, inte
	bcf 	intcon, gie     ;disable interrupts


;****************  Clear Variables  *********************

	clrf	porta
	clrf	portb

;****************  Simple Code  *********************

wait	bcf	portb,2       ;off led
	btfsc	porta,2       ;check if switch is press
	bsf	portb,2       ;on led if switch is press
	goto	wait          ;loop back

end
I use a 20mhz crystal, then i test out all the 3 chip. They produce different results. 1 of the chip did lit up the desire led when i press the switch, but lit up some of the other leds in portb(not all). The other 2 chip produce the same results. Thought they never lit up any other leds in portb, portb's pin 2 led flash dimly, on and off itself. sometime it turn on fully and stuck there, sometime totally off and respond when i press the switch. I really dun know what happen. I never encounter this before. Could it be the chip i bought got problem? I bought them thru farnel, should not have problem right?
 
i dont think it is the chips , probably not..
i am a bit rusty on the code as i have generators on the brain,
if you use the code button you can just cut and paste your code into your posts..
 
williB said:
i dont think it is the chips , probably not..
i am a bit rusty on the code as i have generators on the brain,
if you use the code button you can just cut and paste your code into your posts..

Thanks, me just edit the code area.
 
Nigel Goodwin said:
Is your hardware all OK?, you do have the two required capacitors on the crystal?, and you do have a pullup resistor on the input pin?.

Hm, well as i say previously, i alreadly set up nicely for my 16f84a. Everything is running perfect until i exceed 1k code then i decide to change to another chip, stright away after i change the chip, it failed to work. So i decided to make a very simple code to test out, and i got these result. I never change any hardware since i work with my 16f84a since the configuration for my 84a & 648a should be the same. I am using 20Mhz cyrstal with 2 22pf cap. i have 3 switch for portA pin0,1 & 2. All with 10K tied to gnd and switch to vcc 5v. All led are tied with 220ohm res. Any solution?
 
Hi, sorry guys for bring up a history topic.

These few days i went back and try back this program and found the cause of it. The problem is because i am using a 20Mhz crystal. I change the crystal to 10Mhz for 16f628a/16f648a(i got both to try out now) and it works perfectly as the same as my previous 16f84a. Just that the program speed is decrease by half(i do not want that).

My 84a chip works perfectly with a 20mhz crystal & 10mhz. I also try switching 22pf & 30pf caps. All config works perfect for my 84a chip.

Next i switch to 16f628a, when running with 10Mhz it works perfect except for speed difference. When i switch to 20Mhz(which is wat i need), the output totally is not wat i want. It also dun seems to react with my input. switching the 22 & 30pf caps seems no difference to me also.

Then i rewrote a veri simple flashing led program with no input required and test it on my 628a. When running 20Mhz, the output is still corrupted. I switch back to 10Mhz, it display wat i am programming for. Form the above test, i conclude that the problem is cause by 20Mhz crystal.

I went down to buy another more expensive different brand 20Mhz crystal and test it again. Results is the same. All the output is corrupted. I refer to the spec sheet and i was told all 84a, 628a & 648a support until 20Mhz crystal when using the HS_OSC config word.

Base on my situtation, any recomendation for me.

PS: i need to use 20Mhz crystal for speed in my project. Thanks in advance.
 
Are you sure that the 628 & 648 are capable of running at 20Mhz? There are different revisions (eg LF one's), and some of them are limited to 4 or 10 Mhz. This might be the problem.

PS: Don't forget to check your supply voltage, because the lower the voltage, the lower the maximum frequency you can use.
 
list p=pic16f648a
include p16f648a.inc
__config _hs_osc & _lvp_off &_wdt_off & _pwrte_on & _cp_off &_boden_on
errorlevel -302 ;Eliminate bank warning

Have you checked in MPLAB under config - configuration bits to ensure that you complier directives are settting the config bits correctly. I had a simular problem and that was the cause.
 
Jay.slovak said:
Are you sure that the 628 & 648 are capable of running at 20Mhz? There are different revisions (eg LF one's), and some of them are limited to 4 or 10 Mhz. This might be the problem.

PS: Don't forget to check your supply voltage, because the lower the voltage, the lower the maximum frequency you can use.

Thanks for your help! Anyway i am using "pic16f628a i/p" chip bought from farnell. i bought 3 pieces and all give me the same thing. I check the datasheet for my package and it say the max freq is 20Mhz.

My supply voltage came from my 12v powersupply which i later step down to 5V using 7805 chip. So the input to my pic should be around 5V which i think will be high enuff for 628a.
 
PicChristmas said:
list p=pic16f648a
include p16f648a.inc
__config _hs_osc & _lvp_off &_wdt_off & _pwrte_on & _cp_off &_boden_on
errorlevel -302 ;Eliminate bank warning

Have you checked in MPLAB under config - configuration bits to ensure that you complier directives are settting the config bits correctly. I had a simular problem and that was the cause.


Yup, thanks for pointing this out as i forgot to mention. I did change to the apporiate chip in the "configure device" section each time i use a different chip. Also i did set the cmcon to 7 setting. Others i think should be working normal as how i use a 84a chip since i never had any problem with my 84a chip before.
 
Are you using the same pcb board you have used for 84 ? You might try to put the 84 to your new pcb to ensure it's ok. Check if your pcb's oscilator circuit doesn't have long connection to ground or is passing near high speed logic.
 
Jay.slovak said:
Are you using the same pcb board you have used for 84 ? You might try to put the 84 to your new pcb to ensure it's ok. Check if your pcb's oscilator circuit doesn't have long connection to ground or is passing near high speed logic.

I am currently using a breadboard to do all my connection, so basically i can interchange the chip anytime i want during the experiment phase. My crystal is connect directly to pin 15&16.
 
Ok, i finally found and fix my probelm. I like to share it with you all so next time no one will follow my stupid mistake again...

I conduct a few test before i finally prove my mistake.

First, i change my powersupply. All along i am using a laptop style powersupply which gave me 12V, 1A DC supply, step it to 5V with 7805. For somehow i was lucky and been force to use another DC supply, those lab kind adjustable voltage.

I adjust to around 7.5V for my 7805 which i think should be enuff. I on it and it works!!! My 20Mhz works with my 16f628a finally without any problem. Later i adjust it to around 12V and try it again. It still works. So i narrow down to my problem is caused by my laptop kind powersupply.

I later then remember that i actually need to put 2 0.1uf caps to works with 7805 for certain applications(since i never do so previsouly). After the 2 caps have been place with 7805, it works perfectly! Even with my laptop powersupply. I conclude that the 2 caps are important as i previosly ingore them since i dun have any problem with my 84a.

By looking at it, this maybe something you all may like to consider when upgrading from a 84a chip to 628a/648a chip. 84a seems to works even without the 2 0.1uf caps when using 7805 running in 20Mhz.

Hope my experience helps! Feel free to point out anything if you think i am wrong.
 
You should ALWAYS have those two capacitors on 78xx regulators, otherwise they will tend to oscillate under some conditions - this is obviously what was hapening to you.

You may have used them previously, and they (apparently) worked fine, but it's a problem waiting to happen - under slightly changed load or supply conditions it's likely to fail!.
 
So, as I told you, always check your power supply. Seems like 84's are less sensitive due to their older design. :shock:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top