Implementing a changeable lookup table in C for PIC32

Thread Starter

Sensacell

Joined Jun 19, 2012
2,452
I am designing a DMX LED dimmer around the PIC32MX110F016B part, using MPLAB X and XC32 compiler.

The idea is to use a lookup table to map the incoming 8 bit DMX brightness values to 12 bit PWM values stored in a table.
This scheme will allow me to implement LED gamma correction for much improved brightness linearity.
My program needs 3 tables of 256 values each, one for each color -(R-G-B). Each table entry can be a 32 bit word, but I only need 12 bits of resolution.

I am a veteran assembly programmer and have written this code before in assembly for the PIC18F series parts.
It was simple to use an ORG statement to locate a table of values created using DT or DW (define table or define word)

Programming in C totally freaks me out - I feel like I have NO IDEA what is going on under the hood, like I did in assembly, the compiler just holds my hand and leads me into the dark.

I know I can simply create a STATIC CONSTANT array in C, that seems simple, but I need to be able to change the data by erasing and re-writing the flash memory in the field, using the serial port and a special command mode.

1) How can I tell the compiler where to locate the STATIC CONSTANT array so I can erase and re-write it later?
It should be located on a page boundary so I can block-erase the table before writing new values.

2) Can I use in-line assembly to do the same trick? then use a crude pointer trick to fetch the values?

3) How do I tell the compiler to not use that memory area for other code?
 

Picbuster

Joined Dec 2, 2013
979
Write eeprom use eeprom_write(location, Data_Byte);
read eeprom use Start_Sync=eeprom_read (location);
all things with int's on en off etc are taken care of in the microchip compiler.
I use it all the time happy as I can be.
 

Thread Starter

Sensacell

Joined Jun 19, 2012
2,452
Write eeprom use eeprom_write(location, Data_Byte);
read eeprom use Start_Sync=eeprom_read (location);
all things with int's on en off etc are taken care of in the microchip compiler.
I use it all the time happy as I can be.
Ok, but the PIC32 has no EEPROM? only FLASH.
 

dannyf

Joined Sep 13, 2015
2,197
Programming in C totally freaks me out
For your questions, assembly vs. C makes zero difference. Whatever you were doing to solve your problems in assembly is exactly what you do in C.

So the simplest way is for you to post the assembly code and ask people to convert it to c for you.
 

ErnieM

Joined Apr 24, 2011
8,007
I did some tricks like this a few years back using (non X) C32 when making a bootloader program. Bootloaders are small programs that run in a small section of ROM and load the larger section of ROM to update the main program. Mine happened to load off an SD card but examples abound when using RS232 serial or the USB bus, they even have custom apps if you are loading off a PC.

XC32 is very different from what I did, and even then a seemingly minor upgrade broke all my linker scripts. Going from C32 to XC32 would need a new set of methods to do the same thing.

I'm hand waving because I just never followed Microchip into their latest and greatest compilers, libraries, and code examples. Perhaps asking in the Microchip forums may give a better answer.

Oh, and C is all about "crude pointer tricks." It does them flawlessly, and they work even better on the PIC32's over their other devices.
 

NorthGuy

Joined Jun 28, 2014
611
its for the software the same thing.
Not exactly. In PIC16s you can read/write EEPROM byte by byte. In this PIC32, if you want to re-program something, you need to erase the whole page of flash - 1024 bytes, but fortunately you can program it 32-bit at a time.

It is not hard to figure this out if you read the RTSP part of the manual. It may be convenient to use memory from the boot sector (if you have enough), because the large part of it is not used by the program.
 
Top