PIC12F1501 - Help with writing & reading flash memory
For my project, using PIC12F1501, I am using NCO peripheral to pulse my circuit and I will be operating it at 2 modes of operation, namely, Calibration mode & Normal operation mode. The underlying circuit operates best at a particular frequency and to find out that particular frequency, I need to have a frequency sweep once in lifetime, store that frequency value in flash and every other time, it operates in normal operation where it fetches the operating frequency from the flash. The switch between calibration and normal operation mode is done by a Digital input.
- Sweep the NCO frequency from 800kHz to 999kHz at a duty cycle of about 50% using PFM mode
- Find the best operating point (using AN pins)
- Store values in Flash.
- Read the values from flash
- Initialize NCO frequency values with the read variables
- Do other functions.
As mentioned before, the calibraiton is done only once and the value has to be stored in a particular location in flash. Every other time, when the circuit is (re)started, the normal operation mode reads the flash and initializes the NCO accordingly.
I tried using the routines given in memory.c but the FLASH_WriteWord() requires me to declare a variable unit16_t ramBuf which already takes 32 bytes and with other declarations, i am running out of space. I tried to modify this write word as below, but still i wasnt able to get it working.
Could someone help me to write 2 16bit data in the flash only during calibration and can be fetched while normal operation mode.