hi all,

I have been playing with the PIC16F84A for about of 1 year. But in the last 10 months I left playing with it again. And I had a problem that I lost all the code I have written for this micro controller.

The problem is that I just want the basic module for coding.
the main structure of the code to use for programming in it.
I use MPASM.

please help,
And thanks,
Amr
Posted on 2004-04-07 12:27:25 by amr
I wrote a very dumb test just the other night for a 16F84A...

Here you go...
	list		p=16f84a

#include p16f84a.inc

IDLOCS CODE
dw 0x0103
dw 0x0204

CONFIG CODE
dw 0x3FFA

STARTUP CODE

goto main
nop
nop
nop
goto main

PROG CODE

main
bcf STATUS, RP0
clrf PORTA
bsf STATUS, RP0
movlw 0x1C
movwf TRISA
bcf STATUS, RP0

main2
movf PORTA, W
xorlw 0x01
movwf PORTA

movf PORTA, W
xorlw 0x01
movwf PORTA

movf PORTA, W
xorlw 0x02
movwf PORTA

goto main2

end


I wrote on MPLABE IDE v6.40. Statements like 'CONFIG' and 'STARTUP' are defined by the linker script file '16f84a.lnk' that comes with with the software.

This example generates a 25% duty signal on PORT A0 and a 50% duty signal on PORT A1. (At roughly clock rate/4 frequency)

Regards,
NaN
Posted on 2004-04-07 16:43:35 by NaN

I wrote a very dumb test just the other night for a 16F84A...

Here you go...
	list		p=16f84a

#include p16f84a.inc

IDLOCS CODE
dw 0x0103
dw 0x0204

CONFIG CODE
dw 0x3FFA

STARTUP CODE

goto main
nop
nop
nop
goto main

PROG CODE

main
bcf STATUS, RP0
clrf PORTA
bsf STATUS, RP0
movlw 0x1C
movwf TRISA
bcf STATUS, RP0

main2
movf PORTA, W
xorlw 0x01
movwf PORTA

movf PORTA, W
xorlw 0x01
movwf PORTA

movf PORTA, W
xorlw 0x02
movwf PORTA

goto main2

end


I wrote on MPLABE IDE v6.40. Statements like 'CONFIG' and 'STARTUP' are defined by the linker script file '16f84a.lnk' that comes with with the software.

This example generates a 25% duty signal on PORT A0 and a 50% duty signal on PORT A1. (At roughly clock rate/4 frequency)

Regards,
NaN


May I ask one question, hope I'm not bothering ya amr, but I'm not sure what you guys mean when you say "duty cycle" can you explain? Thanks :D
Posted on 2004-04-07 19:11:20 by x86asm
No problem. Duty cycle sounds like something more than it is.

The program I wrote loops endlessly. There is XOR's in there which will toggle bits on every pass of the loop. So its fairly safe to assume that the output generated will be some repeating pattern, at a frequency that is proportional to the clock rate of the program.

Duty cycle comes in as follows:

(1) It assumes your talking about a repeating signal with some frequency.
(2) The on-time / period time in every cycle ammounts to the "Duty Cycle".

Thats it. I was actually wrong in my estimates above. The code has three fragments in the loop:

(1) Pin one Toggle
(2) Pin one Toggle
(3) Pin two Toggle

(Start over again)

In one pass of the loop turns pin one is turned on and off, so it repeats at some frequency. As well its on for 1/3 the time, hence its simpler to say the generated signal has a 33% duty cycle.

Pin two however, only changes state once every pass of the loop. So it takes two full passes to cycle once. So its effectively on 1/2 passes, or 50% duty cycle.

Its interesting to note here that the frequency of each are different. Pin one's frequency is twice pin two's, since it takes two full passes to generate one cycle. As such you should realize that a stated duty cycle is totaly independant of the freqrency of the signal it describes.

Hope this helps...
Regards,
:NaN:
Posted on 2004-04-07 21:25:16 by NaN
Try to use the templates that come with MPLAB. There is one for each device, including 16F84.

As far as I know, the location of the templates is as follows:

For MPLAB ver 5.xx
C:\Program Files \Mplab \Template \Code

For MPLAB ver 6.xx
C:\Program Files \MPLAB IDE \MCHIP_Tools \Template \Code

If you lost these too, you can download the latest MPLAB and install it. The templates will be there.
Posted on 2004-04-08 11:27:04 by VVV
Thank you all for your help,
thanks
Amr turk
Posted on 2004-04-09 08:23:34 by amr
I use "Debug.exe" to program the PIC. There are so few instructions in this RISC processor that it is quite easy to program it in machine code. Code it in Debug then use Bin2hex.exe to convert to Intel hex standard file format.
Posted on 2004-04-09 22:56:00 by mrgone
I think VPP is 12 volts unlike Intel's smart voltage flash. What did you use for 12V if so? A DCtoDC converter or a PC power supply...lol a little joke meaning of course two supply voltages. Because I did attemp a programmer once but time contraints forced me to buy theirs Mine was not an 100% and I couldn't pull it out of them. I think had something to do with set up and hold times.
Posted on 2004-04-09 23:17:12 by mrgone
I use "Debug.exe" to program the PIC. There are so few instructions in this RISC processor that it is quite easy to program it in machine code. Code it in Debug then use Bin2hex.exe to convert to Intel hex standard file format.


use "debug.exe"
wired way to program a PIC.

:notsure:
Posted on 2004-04-10 05:47:12 by amr
Im quite happy with my MPASM. However using debug sounds interesting.

As for power supply voltage, i had a 'wall wort' power supply that gave me 14 volts out. So i used two regulators, a 7805 & 7808 to build two voltage sources, +5 and +13 (5+8).

There is a charge pump circuit that the PIC Kit uses. It uses a PWM output to drive a switching LC circuit that 'pumps' charge on to a capasitor. The more charge, the more voltage created. This cap has a voltage divided on it where the ratio'd voltage is read by a PIC chip with A/D. Internally, the voltage read is compared with the designed set point and the chip adjust itself for faster or slower switching (to sustain 13V). Its the basic principal behind switch mode power supplies (such as your CPU power supply).

Check it out if you like:

Tip No. 17 : Boost Power Supply

Enjoy.
:alright:
:NaN:
Posted on 2004-04-11 10:27:44 by NaN
Me too, I like the MPLAP it's a pretty good tool.


There is a charge pump circuit that the PIC Kit uses. It uses a PWM output to drive a switching LC circuit that 'pumps' charge on to a capasitor. The more charge, the more voltage created. This cap has a voltage divided on it where the ratio'd voltage is read by a PIC chip with A/D. Internally, the voltage read is compared with the designed set point and the chip adjust itself for faster or slower switching (to sustain 13V). Its the basic principal behind switch mode power supplies (such as your CPU power supply).


I don't understand what's going on here.

Amr
Posted on 2004-04-12 07:40:58 by amr
Did you download the PDF? It also has a description of how it work, with some theory as well. Perhapse this will help you out? If not specifically what part do you not get?

PS: I ment to say voltage divider, not voltage divided. Again, this is also reitterated in the Above noted tip.

Regards,
:NaN:
Posted on 2004-04-12 11:54:38 by NaN
The charge pump is a DC to DC converter circuit I do beleive. It stems from the basics that voltage mutiplier circuits based on the diode voltage doubler can be used to increase voltage. Of course the input signal must be AC so the chip has an oscillator and must also be strapped with a current bypass Xsistor to accomodate the necessary load requirements. The large capacitors are used to store sufficient voltage and in conjuction with a resistor create a slow time contant to keep sudden load variations from pulling down it's output voltage.
Posted on 2004-04-12 13:10:05 by mrgone
I guess you could say its a DC-DC converter, but term "doide voltage doubler" is something I havent heard befor? Perhaps this is something different I havent come across yet. (I've never played witha DC-DC chip yet, perhaps this is how they work?).

As for the above circuit, I can describe its action in laymans terms. The diode has an important role, but it doesn't directly determine the voltage generated.

The whole thing works because of the effects of the inductor. An inductor can be viewed as a big cement flywheel. The thing takes a bunch of energy to get spinning, and will not spin right away because of its weight. Once going, it has momentum. As such when you want to stop it, it as well will not stop right away, and the energy needs to be drained off it by breaking somehow.

In the circuit, the inductor is energized when the transistor is switched on. The voltage "pressure" on the inductor drives the current that flows through it. The current, like the flywheen analogy, will not start right away, and needs to build up "momentum" to overcome the inductor. Assuming all things zero initially, the doide is pulled to near ground and will not conduct. It can be seen as a check-valve, that will only operate if not grounded by the transistor.

When the transistor is switched off, whatever current generated, like the momentum of the spinning wheel, will continue to flow and voltage "pressure" will be generated. Since the transistor is off the only place for the "rush" of current as the inductor dies down is through the diode. Once through the diode "check valve" the energy is stored on the capacitor. The more charge stored, the more voltage generated across it.

Voltage is like pressure in electrical systems, so the diode really acts like a pressure check valve, allowing more pressure to be pumped in only. The voltage will continue to rise unless there is a load to releive it. The capacitor itself is not perfect and will "drain" some current on its own at a specific rate. By adusting the time the transitor is on vs off, you can adjust the ratio of "applied pressure" through the diode vs the rate of "discharged pressure" from the capacitor and other circuit loads.

If your following thus far, you should be able to see that this has an interesting property. The voltage is directly proportional to the switching duty of the transistor, and the discharge rate. Discharge rate is essentially your circuit loading, which can vary significantly. This means you can maintain a steady voltage as you add more load, and pull more current from capacitors if and only if you increase the switching duty. This is where the PIC processor comes in! It loads the output voltage with a voltage divider and at 13V it will measure in its A/D input a scaled value in the range of 4.5V. (4.5 == 13V). This is because the A/D inputs can not span to 13V, a limitation in the chip.

As more current is loaded in the circuit, the capacitor voltage "pressure" will drop, and so will the value read by the A/D input. Once compared to a set point that equals 13V in the chip, it will know to increase the switching duty in the output PWM, allowing more current to develop across the inductor while the transistor is on. Then through its built up current "momentum" it will pump more charge into the capacitor and circuit loads, such that the circuit Voltage (or circuit pressure) increases again towards the setpoint of 13V.

I hope I'm getting the idea across here. Its a somewhat basic system in principal. It only requires monitoring to control the amount of energy needed to be pumped in to maintain a constant voltage. Since a PWM has a constant period and only vaires its duty cycle, this works quite nice! Under no-load, the PWM will have a very low duty cycle (only pumpin enough to sustain the voltage divider & capacitor drianing of "voltage pressure"). Under higher current loading, the PWM will have a nearly 100% duty cycle to sustain 13V and supply all energy used through out the circuit(s).

As im sure you'll get at this point. There is a limit of how much energy you can provide. When the PWM is at 100% duty your maxed out!. For very high current requirements you need bigger and better inductors, to increase the size of your flywheel ;) . However other problems of effectively "driving" these flywheels come in which is why your PC power supplies are so bulky ;) . Likewise, the currents that drive the larger "flywheel" inductors in power supplies tend to create heat off the inductors internal resistance (you can think of this as the bearings on your flywheel getting hot). This leads to the need for power supply cooling fans (so your flywheel doesnt catch fire ;) )

I hope this dumbs things down a notch for everyone.
Regards,
:NaN:

PS: Ratch & anyone else who wishes to point out my abuse of physical concepts, please do not correct me. I will let everyone know now that I'm loosly basing analogies such that the mathematics and dynamics involved can be envisioned in concept only. For a pure and correct description there are many texts that does this, or google for "switch mode power supplies".
Posted on 2004-04-12 22:55:27 by NaN
You must become familiar with a voltage doubler. This will widen your scope of theory. Are you famaliar with ARRL Handbook? You will see examples there. You know I have found that the old timers have so much knowlege to give. You know I am utterly amazed at how hams were able to invent and empliment single side band. They had no crystal filters or mechanical filters(range 455KHz) or even crystals yet they were able to understand that an AM signal was comprized of a carrier and two side bands. Then understanding that the intelligence was contained also in both side bands but not detectable. They conceived an elaborate network of diodes and resistors to create a phase shift network that could completely remove the carrier and one sideband. Wala! A signal one third the spectral band width and even more important an efficient signal that would not even stimulate the linear amplifiers unless there was modulation. In other words, No talk/no output. Wow! But how do you receive this signal? By re-inserting an imitation carrier inside the receiver know as the BFO(beat freq osc). Trust me if you delved back to old theory you would be amazed at the new discoveries waiting to be patented. Did you know that ham radio operators invented the first digital computer unless you want to say it was the weaving loom. You must learn the voltage multiplier.
Posted on 2004-04-12 23:52:24 by mrgone


Found one! Your right this is very basic. Im sure i saw this before in my travels, but never really stuck with me. To be honest, I probably wouldnt use this circuit as it won't sustain any serious loading, not without a battery of capasitors on either side.

But thanks for the idea, you convinced me to go and google for it :alright:

Regards,
:NaN:
Posted on 2004-04-13 17:56:09 by NaN
See? Beleive it not there is some of that circuitry in the charge pumps or DC to DC converters and yes Don't the charge pumps use some fairly hefty capacitors?As far as the load goes a high current pass Xsistor is used. Usually a PNP strapped in a common base configuration. Basics are the building blocks of electronics and are important to a strong foundation. I've always said that you may know every Johnny come lately trick in the book but if you can't grasp a strong understanding of Ohm's Law such as being able to Thevinize or Nortonize a circuit or black box then your like a wobbly building with a weak foundation.
Posted on 2004-04-13 20:56:37 by mrgone
you can use this circuit to generate a -ve DC voltage from a +ve DC voltage.
Posted on 2004-04-14 00:01:35 by amr
Nan,
I got what you want to make here.

I think you want to make DC motor controller that maintain the DC motor speed whatever the . Is this right?

If so I have an idea.

I use a tachometer...............................
I connect it on the DC motor and then take it's output and put it on a F/V and then compare the voltage with a ref. voltage I generate. if higher then the output is low and stop supplying power to the motor. untill it goes to a lowwer speed then it gives power again......... and so on it maintains the the speed.


I know you have used other technique.

Regards,
Amr
Posted on 2004-04-14 00:09:49 by amr
Thanks for the tip, but im not up to doing any of this at the moment :grin: . It was you how asked how the switched mode power supply worked in Tip #17. Then we hijacked your thread and got gabbing on other ways of scaling voltages.

But again, thanks for the tip. Using tachometers is a really good way of controlling moter speed, as well as position. :alright:

Regards,
:NaN:
Posted on 2004-04-14 18:40:38 by NaN