PIC Programmer Writes To EEPROM - microcontroller

I am programming a software which I am developing at the moment, to the PIC18f46K80 by TNM 2000 universal programming. When I read back the PIC, I see that the EEPROM has been written some data. This data is which my software writes to the EEPROM under some conditions. I want the EEPROM to be completely clear when I first program the mcu. I have never seen or realized that a programmer to write to eeprom while loading the software to the pic. Do you have any ideas about why this happen?
Thanks.

Assuming you are using MPLAB X for PIC programming, there should be a "Preserve EEPROM Memory" checkbox in your PICkit configuration.
Make sure its not ticked.
Additionally, you may select the "EEPROM" checkbox to make sure the EEPROM gets erased.

Related

ESP32 CAM - EEPROM / sdcard / non erasable memory - beginner problem

Overwiew
I am working on my first project with ESP32, I have ESP32 CAM model and I am creating an automatic roller blinds. I got most of the project working - I have web server that controls continous servo and all mechanics. I want to be able to adjust the time for going up-down without reprograming the microcontroller. The goal is to have an automatic roller blinds with alarm clock function.
Problem
I need a way to reliable save/read data to store variables state, even without power. How to achive it with ESP32 CAM?
Additional info
On Arduino board that would be EEPROM, and I found some tutorials that claim that EEPROM can be used on ESP32. However, when I tried using EEPROM, it looks like the values are overwritten while bootloading. So I guess ESP32 CAM needs different approach. Correct me if I am wrong, please.
Ok, so user bvguy on Reddit solved my problem.
"EEPROM is deprecated. They want you to use preferences now. Here is an example ."
I tested the example and it works on my ESP32 CAM, therfore solving the problem.

Why do we need to select a board to work with arduino IDE

I always wondered how this works . In arduino IDE we have option to select different boards because the code upload i guess is different ? Also there is possibility to even add board manager url to add other boards.
Why uploading the code is so different from board to board , and what exactly differs there ? The code is sent to via serial connection and i understand that a board might have different chip for handling USB to serial but ..
Can someone explain as clear as possible , how the code is uploaded to a board and why there is no generic way , why so many configurations.
Thanks and sorry if is a dumb question.
One of the important things that selecting a board does is, as you say, inform the IDE of how to load code onto the board. Perhaps more importantly, the board definitions give you the logical mapping of the board's hardware to the code constructs you are using to program against. For example, have you ever wondered what happens when you use a constant like PIN_13, or how that constant maps to a physical pin on your board, which has a trace to some contact on the microcontroller chip itself?
There is a lot of other code you don't see, much of it in the board definitions (and some in the Arduino core) which lets you work with relatively direct concepts (like pin numbers and modes) in the code that you write or edit.

A way to change mcu program from the outside

We need to change a controller code from the out side as they do with industrial MCU .
So that you have an mcu,with a program on it, and someone can program some "words" to it, that will determine how it works.
So for example you can program an mcu -not with a programer but with some inputs from serial, to do some simple things such as:
if input A==1
b=1
I wonder if there is a smart way to do that with simple software on the mcu, that it has many #defines for various commands, and it perform them according to values it gets from the outside (and saved for the rest of the program).
I wonder if the industrial programers are using that method, or that every programing of a user is actually load a code(.hex) to the chip(with internal programer ) .
I prefer the simplest way(i wonder if its by pre defined software)
A couple of options come to mind so hopefully this answers your question. It sounds like the simplest version of your question is "How do I change the behavior of the MCU without an actual MCU programmer?" A couple of options come to mind.
1) Depending on the MCU you can have a bootloader that is essentially a small piece of code programmed in the MCU by a programmer that has the ability to reprogram other parts of the MCU. This doesn't require a programmer but involves some other form of letting the bootloader know what the new code is (USB, Serial, SD Card, etc). This will only work if the MCU has the ability to self flash.
2) Again, depending on MCU and scenario you could program a generic set of rules that carry out functionality based on the inputs given to the MCU. This could be in the form of IO pins, EEPROM, or a domain-specific script on an SD card that the MCU can read and interpret at runtime.
Both options depend on the MCU you are using and what hardware capabilities you have at your disposal. But you certainly have options other than reprogramming the end hardware with an actual programmer every time you want to make a change. Hopefully that helps.

Micro-Controllers Programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I bought an Inductance sensor that is used to detect cars for using it in my current Project, my question is: How do I program this sensor or interface with it to read data from it, what is the approach, which programming language should I use and how?
Check out Arduino, it is a good place to start, it is programmed in the C language.
Check out thier website: http://arduino.cc/
I reccommend you get a Microchip PIC microcontroller. Make sure that the PIC has an analogue input and digital output port. You can connect the sensor to the analog input. This input is convertered by the internal ADC and you can read this into your program.
Use the Microchip IDE for programming. You can either do this is Assembler or C. Assembler is a set of machine instructions and C is more high level.
Read this website: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=81&redirects=developmenttools
If we are all going to answer with, hey try this microcontroller I might as well throw in a few:
The msp430 has a very clean and simple instruction set, and good tools. at $4.30 you might as well buy the max 3 per order and just have them for a rainy day...
www.ti.com/launchpad
For about $20 you get everything you need in this one package:
http://www.st.com/internet/evalboard/product/252419.jsp
massively more powerful than the pic or avr for half the price of a normal entry level arduino.
There are a couple of pic32 (which is really a mips not the traditional pic instruction set) boards in the arduino price range.
I have and like arduinos and cut my teeth on pic's before moving on, dont get me wrong they are fine, have their pros and cons.
go to http://www.sparkfun.com to find tons of things, developer microcontroller boards, and perhaps interfaces to the sensor you are interested in, etc.
The real answer to your question is not what is my favorite microcontroller or board but how do I use this sensor. When or before purchasing you should have figured that out. You need to research how those sensors are used, what if any sensor specific hardware or circuits are needed, etc. You might find a turnkey package at sparkfun for example or some other arduino shield that just does everything you need. Or perhaps a different sensor type that performs the same function.
I am guessing you are going to need to sense current in some form or fashion, do some googling on inductance and inductors. You might want to put a small precision resistor in line with the inductor and measure voltage across it using an ADC in a microcontroller or a standalone adc hooked to a microcontroller or something else. Depends on the precision you need, you might need more than a microcontroller can provide. Which gets into how do I interface a spi or i2c ADC. You might want more than a small resistor to avoid melting down the sensor or circuit...
If you dont want this question to be closed and sent to electronics.stackexchange then you need to edit your question and provide a direct link to the sensor you purchased. If it is just an inductor then you have to add more circuitry if it is a full sensor package with a serial or parallel interface (spi, i2c, rs323) then that is a programming question but you still have to then decide on what microcontroller you want and ask how do I do i2c in an arduino for example (of which there are many web pages).

Communicating with the Pic 16F913

Here is my issue, it appears that all the communication lines for the PIC 16F913 reside on the same set of pins, this is convenient in that I don't have to sacrifice GPIO pins just to do comms, however the problem I'm having now is if I'm using the SPI on the chip, how can I send information to the RS232?
The reason this issue came up, is that I just bought a CAN bus chip that communicates over SPI, and I would really like to see the data on RS232, so I can see messages. (I really don't know much about CAN yet, so who knows if this even makes sense yet).
Here are the options I see, and maybe someone else has better ideas that I'm just simply missing.
Somehow setup a time scheme that will switch between SPI and RS232 every time I get data,
-- This doesn't seem hard and should work, but supposing I don't want to miss a message, what if a message is written while I'm writing to RS232, is it possible I'll miss it?
2.. I can always use SPI, but then build my own comm bus over 8 of the GPIO lines, to another PIC 16F913, using only the GPIO lines and then since the RS232 lines are free on the second PIC I can simply read the data and spit it out.
-- This one is doable but now we're wasting 2 chips, AND all the GPIO lines,
There has to be a better way. Or is there?
Any help is greatly appreciated.
Update: I would like to clarify, obviously one solution is using a completely different chip (which may in fact be what I end up doing, if I can get the 18F programmed), however, I'm interested in worst case scenario, in which I am limited in resources and only have some 913's, is the way described above the only way to do it with this chip, or is there a better way?
You could do a software implementation of the SPI bus - it's easier to do than the UART because the timing isn't critical and you are in control of it.
Most CAN chips have a few receive buffers so if you're busy doing something with the UART then the messages will be buffered inside the CAN chip. But... you will need to make sure that you can get the messages out of the CAN chip fast/often enough so you don't lose some.
You would probably have to either use an interrupt for the UART Tx process - so that you can be receiving CAN messages while you're sending data on the UART.
If you're only interested in certain messages most CAN chips have filters - this makes it easy to only receive the messages you're interested in, usually dropping the number of packets/second dramatically.
You can use a software implementation of a RS232 port. For example the c compiler from http://mikroe.com comes with such a library. But it shouldn't be too hard to shift bits to an output pin, rs232 is a fairly simple protocol.
I strongly recommend that you change the MCU with PIC16F1933.
It is newer
It is cheaper
With EUART and MSSP moduls.
The MCU arhitecture is impruved.
The PIC16F913 MCU will become obsolete in next few years!

Resources