hi all,

I wanted to make an intelleigent system that changes it self according to the surroundings. So, to make so I want to know a why that I can reprogram the program memory of the PIC from the code is that possible or impossible at all???

Best regards,

Amr Turk
Posted on 2004-04-28 13:04:44 by amr
I think it's impossible (at least for the xxPICxx 's I know) - the code is in ROM, 13-bits-wide instructions iirc (can't put them in RAM) . I hope I'm wrong , I've read about only a few PICs ^^"
Posted on 2004-04-28 16:27:38 by Ultrano
Which PIC are you referring to?
FLASH devices will allow you to do that.
Posted on 2004-04-28 19:11:38 by VVV
FLASH really,
I have PIC 16F84A
and it's flash
then how can I do so?

Amr Turk
Posted on 2004-04-29 10:48:21 by amr
Sorry, the PIC16F84A, although a FLASH device, cannot program its own program memory. This is possible, however, with other devices (for example 16F87x or 18F8xxx families).

But FLASH memory is usually updated with new firmware under the control of a bootloader, which also resides in FLASH and which controls the download (over a serial port, for example) and programs the rest of the FLASH one sector at a time. But it is the user who supplies the new firmware. The micro is not able to actually "develop" a program and then program itself with it.

Anyway, the EEPROM is writable during normal operation, so you can use it to store environment-dependent variables and write your program to take them into account. This way, the micro will react to a changing environment.
From what I understand this is what you want to do.
And I think this is the correct approach, since writing the FLASH would only help if you were to store data in it.
Posted on 2004-04-29 11:41:19 by VVV
thanks for your help
Posted on 2004-04-30 22:39:49 by amr
I think I have found a way, I just make an external circuit that's activated when it recieves a pulse from the PIC that contain an EEPROM that contain the program. so when the pulse is applied it just send the program to the PIC using the In-Circuit programming feature in the PIC. And if the PIC progarm want to change the code it just change the program inside the EEPROM. and then reprogram it self. ...........................

Intilliegence is coming we can't stop the Machine invation.....

Posted on 2004-05-22 11:20:15 by amr

I think I have found a way, I just make an external circuit that's activated when it recieves a pulse from the PIC that contain an EEPROM that contain the program. so when the pulse is applied it just send the program to the PIC using the In-Circuit programming feature in the PIC. And if the PIC progarm want to change the code it just change the program inside the EEPROM. and then reprogram it self. ...........................

Wouldn't it be LOTS easier to just use an exterrnal EEPROM that is made to store (and change) information, and keep your history information there?

Mircochip makes em, even posts the code you need to run them.

(The EEPROMs work on the I2C interface which is well worth learning for its own sake)
Posted on 2004-05-22 14:35:59 by Ernie
I think, I agree with you. That's what I have just written.

but what is the I2C interface?

Mircochip makes em, even posts the code you need to run them.

do you mean that the PIC has a feature that makes it can read it's program or data from outer memory.(i.e. I mean here feature that is made specifically for this not using the ports with some code to do so).


Posted on 2004-05-23 03:43:47 by amr
Hi, amr,

As I said before, you should just store environment-dependent variables in the EEPROM and have your program ACT based on those changes, instead of actually ALTERING itself.

If the on-chip EEPROM is not enough, you can connect an external EEPROM, like Ernie suggested.
But I think Ernie also meant you should store in the EEPROM just variables (history of changes), not an actual program.

If I am not mistaken, the PIC16F84 does not have I2C interface, so you would have to implement it yourself. Takes a little bit of work, but you can learn a lot. Take a look at the specification:http://www.semiconductors.philips.com/acrobat/literature/9398/39340011.pdf
For details on connecting I2C EEPROM's to a PIC, take a look at this link: http://ww1.microchip.com/downloads/en/AppNotes/00567.pdf

But you can also use a 3-wire (Microwire) serial EEPROM, since the interface is easier to implement. Microchip make these, too. Here is the link: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=80 . I would probably choose 93xx46 or 93xx66. For details on how to connect these to a PIC, see this link: http://ww1.microchip.com/downloads/en/AppNotes/00530f.pdf

Lastly, programming the PIC using the ISP is not a trivial task. You need some intelligent device to send the commands, data, do the checking, timing, etc. Take a look at this document: http://ww1.microchip.com/downloads/en/DeviceDoc/30277d.pdf .

I hope this helps.
Posted on 2004-05-25 11:48:01 by VVV
Thanks alot,

but I don't think that changing variables only could change the whole way of thinking of some robot(say). But changing the code (the way the robot think or make dicision) will make it work differently at all. That's what I think.

By the way thanks for the links," but these day's I have no time to read these PDF's, I have exams",

Thanks for All,

Posted on 2004-05-26 04:39:20 by amr
The code will be already in the program memory. But using one section of the code vs. another could mean totally different behaviour. Decisions to use one section or another of that code will be made based on the environment changes. That way the behaviour changes in response to the environment.

A simple (though dumb) example that crosses my mind just now:
Suppose your robot has a light sensor that senses ambient light. If there is light 9 hours a day, the robot "learns" that and says "Good night!" 5 minutes before the lights go out on the following day. But if subsequently the "days" are longer or shorter than 9 hours the robot detects that and adjusts daily the time it says "Good night!" accordingly, to be 5 minutes before "it thinks" the light will be turned off. As long as that happens gradually, say with a vairation of less than 5 min daily, the robot adjusts the time it says "Good night!"

Suppose now that the code also includes a test for when the lights go out much sooner than normal (there is more than 5 min variation). Then the program could make the robot say "Check the lights!" That way, it behaves "intelligently". It "knows" that there must be something wrong with the lights, since they do not normally go out that soon. But this new day duration is recorded and if the next day the lights go out at about the same time, the robot will again say "Good night!" 5 minutes before that. It has "learned" that from now on it has to go to bed earlier.

Stupid example, but I hope you get the idea.
Posted on 2004-05-26 11:35:32 by VVV
I think I have already understood what you have said lately,
but this is good so...................
but you have a limited space and you can't just write the whole code in the memory so you just need to make the change to code....

let us think in your example:
say that you have programmed your robot for testing the light using the sensor,and it "learns" that it can know the difference in time. but you didn't program it to go check the light.

so simply why there is an algorithm that code "I mean teach" the robot that it can go and check the light. so it easily can learn by it self. but using your way..... will limit the robot to detect and do what you only have programmed it to do?
but making an AI algorithm that knows it's features and knows how to use it and make the disicion on how to use it to fit in different situation. will make it "Learn, or Get more Intilligent" program it self to use it's features.

I hope I have made my point clear enough. that's why I'm interested to find an electronic why to do so. but not in finding a solution for specific situation.

Posted on 2004-05-27 09:36:07 by amr
I think your point was clear from the beginning.
But "learning" is really getting the information from the surrounding world and finding a pattern (which is possible because our world is deterministic). More actively, you could take actions and observe their repeatable effect and learn that way. This is what we humans do very often. But we are curious, we are "preprogrammed" to take actions and to observe.
Imagine a child that has never seen a light switch. Until he sees someone flip the switch, he will not know what it's for. Or, alternatively, he can try flipping it by himself and, observing the effect, learn that it turns on the lights.

Returning to your robot, it needs some basic "preprogram" to enable it to develop its knowledge. It does not know that it can go and check the lights. It needs some preprogram to make it move objects and flip switches. Once it finds the one that turns on the lights, next time it will "remember" and will be able to go "check the lights" by itself. To be able to learn from someone else, it would need some means of "seeing" someone flip the switch.

Anyway, I am not trying to discourage you, nor am I pretending to know a lot about AI. These are just my thoughts (coupled with Hume's philosophical views on learning). And I tried to describe something feasible with just a PIC16F84.
Posted on 2004-05-27 11:32:28 by VVV
That's ok,
I think now we some how agree, and get to the same point.

Actually, Yes we have to have something preprorgammed that enables Robot(machine, whatever.......) to understand different situations. But to understand differrent situations it must first start to collect data on different situations and understand it and take different actions based on these data every time(That's what you said and I totally agree with it).

But let us think of the baby learning how open the light switch.
First he sees someone flipping it then, he observes the light have went on. So may be he try it him self. so he knew now that he can open and close the light by flipping the switch up/down. but after many times and he grows up more it seems that it's not a matter of thinking. He just flip the switch up and down. It's just seems that his mind reprogrammed it self after many times of trial and processing of new information(seeing someone flipping the switch and the light opens), That he do it without thinking. That's what I mean exactly.

Now, let's get back to our pic electronics stuff and let's see how can we implement this idea?

I don't want now to know how to code the part that is responsible of understanding and changing code (AI part). But I want to discuss. How to make the pic reprogram it self?

About the hardness of reprogramming,
First I will assume the code has been entered totally without errors so no verification needed.

Second, I replace the PIC with a serial EEPROM and program it as using the pic programming program so it just send the data to the EEPROM. and then we just send it back from the EEPROM to the pic that's all.

Put the pic in in-Circuit programming and program it this way.
but I think there will be errors because the EEPROM don't save timing so the commands send for pic programming may differ.

I don't know.

If any suggestions, please send.

Posted on 2004-05-27 13:18:07 by amr
I think we finally converge to some point in our ideas.
For me, though, it's not programming per se, it's recording CONNECTIONS between actions and/ or objects. You do something, it has an effect, you record them both. Next time when you need to produce the effect look up the action that produced it last time and take that action. (I filpped the switch and the lights turned on; record that; next time I need to turn on the lights look in the table (EEPROM) and see what turns on the lights: it's the switch, flip it).

As for programming, I would use another PIC, such as PIC12xx50x (8 pins), maybe with I2C. Use the I2C to get the data from the EEPROM and the rest of the lines to program the main PIC. To free up 2 pins you can use the internal RC oscillator. I found it works quite nicely, usually within 5% of the nominal frequency. That should be OK for timing the programming pulses. An intelligent device like that will give you all that is needed to reprogram the main PIC (programming, verification, timing).
Posted on 2004-05-28 11:32:12 by VVV
I will see if I can do so.

Thanks for the great discussion,

Posted on 2004-05-28 16:37:58 by amr