chipKIT® Development Platform

Inspired by Arduino™

Help Understanding IO Ports

Created Wed, 17 Aug 2011 17:50:30 +0000 by laelfrog


laelfrog

Wed, 17 Aug 2011 17:50:30 +0000

I'm working on getting the TLC Library working with my Uno32 and I need some help understanding the IO ports.

The Library doesn't compile at the moment due to these missing references:

/Tlc5940/Tlc5940.cpp: In member function 'void Tlc5940::init(__uint16_t)':
/Tlc5940/Tlc5940.cpp:107:5: error: 'DDRB' was not declared in this scope
/Tlc5940/Tlc5940.cpp:107:21: error: 'PORTB1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:107:29: error: '_BV' was not declared in this scope
/Tlc5940/Tlc5940.cpp:108:22: error: 'PORTB2' was not declared in this scope
/Tlc5940/Tlc5940.cpp:109:5: error: 'DDRD' was not declared in this scope
/Tlc5940/Tlc5940.cpp:109:22: error: 'PORTD3' was not declared in this scope
/Tlc5940/Tlc5940.cpp:124:5: error: 'TCCR1A' was not declared in this scope
/Tlc5940/Tlc5940.cpp:124:5: error: 'COM1B1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:125:5: error: 'TIMSK1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:134:5: error: 'TCCR1B' was not declared in this scope
/Tlc5940/Tlc5940.cpp:134:18: error: 'WGM13' was not declared in this scope
/Tlc5940/Tlc5940.cpp:135:5: error: 'OCR1A' was not declared in this scope
/Tlc5940/Tlc5940.cpp:136:5: error: 'OCR1B' was not declared in this scope
/Tlc5940/Tlc5940.cpp:137:5: error: 'ICR1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:155:5: error: 'TCCR2A' was not declared in this scope
/Tlc5940/Tlc5940.cpp:155:18: error: 'COM2B1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:157:18: error: 'WGM21' was not declared in this scope
/Tlc5940/Tlc5940.cpp:158:18: error: 'WGM20' was not declared in this scope
/Tlc5940/Tlc5940.cpp:159:5: error: 'TCCR2B' was not declared in this scope
/Tlc5940/Tlc5940.cpp:159:18: error: 'WGM22' was not declared in this scope
/Tlc5940/Tlc5940.cpp:160:5: error: 'OCR2B' was not declared in this scope
/Tlc5940/Tlc5940.cpp:161:5: error: 'OCR2A' was not declared in this scope
/Tlc5940/Tlc5940.cpp:162:19: error: 'CS20' was not declared in this scope
/Tlc5940/Tlc5940.cpp:164:19: error: 'CS10' was not declared in this scope
/Tlc5940/Tlc5940.cpp: In member function '__uint8_t Tlc5940::update()':
/Tlc5940/Tlc5940.cpp:190:5: error: 'TCCR1A' was not declared in this scope
/Tlc5940/Tlc5940.cpp:190:5: error: 'COM1B1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:190:5: error: '_BV' was not declared in this scope
/Tlc5940/Tlc5940.cpp:195:9: error: 'PORTB5' was not declared in this scope
/Tlc5940/Tlc5940.cpp:204:5: error: 'COM1A1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:205:5: error: 'TIFR1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:205:5: error: 'TOV1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:205:5: error: 'TIMSK1' was not declared in this scope
/Tlc5940/Tlc5940.cpp:205:5: error: 'TOIE1' was not declared in this scope
/Tlc5940/Tlc5940.cpp: In function 'void tlc_shift8_init()':
/Tlc5940/Tlc5940.cpp:342:5: error: 'DDRB' was not declared in this scope
/Tlc5940/Tlc5940.cpp:342:23: error: 'PORTB3' was not declared in this scope
/Tlc5940/Tlc5940.cpp:342:30: error: '_BV' was not declared in this scope
/Tlc5940/Tlc5940.cpp:343:23: error: 'PORTB5' was not declared in this scope
/Tlc5940/Tlc5940.cpp:344:23: error: 'PORTB2' was not declared in this scope
/Tlc5940/Tlc5940.cpp:348:5: error: 'SPSR' was not declared in this scope
/Tlc5940/Tlc5940.cpp:348:16: error: 'SPI2X' was not declared in this scope
/Tlc5940/Tlc5940.cpp:349:5: error: 'SPCR' was not declared in this scope
/Tlc5940/Tlc5940.cpp:349:16: error: 'SPE' was not declared in this scope
/Tlc5940/Tlc5940.cpp:350:16: error: 'MSTR' was not declared in this scope
/Tlc5940/Tlc5940.cpp: In function 'void tlc_shift8(__uint8_t)':
/Tlc5940/Tlc5940.cpp:356:5: error: 'SPDR' was not declared in this scope
/Tlc5940/Tlc5940.cpp:357:14: error: 'SPSR' was not declared in this scope
/Tlc5940/Tlc5940.cpp:357:25: error: 'SPIF' was not declared in this scope
/Tlc5940/Tlc5940.cpp:357:29: error: '_BV' was not declared in this scope

Its pretty clear that constants that reference the Arduino pins aren't available and need to be updated to reflect the right ones for the Uno32.

I found the pinout XLS document (http://www.digilentinc.com/Data/Products/CHIPKIT-UNO32/chipKIT%20Uno32%20Pinout%20Table.xls) but I don't really see how to use it. Are there good examples of IO that I can learn from?


GeneApperson

Wed, 17 Aug 2011 18:03:55 +0000

If you go to the chipKIT wiki, under Programming Hints, there is a section that describes the differences between the I/O Ports on AVR processors and PIC32 processors. I would start there.

The next thing that you will need to do is get the data sheet for the AVR device from the Atmel web site, the PIC32MX3XX/4XX Family Data Sheet and the appropriate sections of the PIC32 Family Reference Guide from the Microchip web site.

The peripheral devices (e.g. SPI, UART) are functionally similar between the AVR and PIC32, but have completely different implementations. The peripheral registers have different names, the control bits have different names, and way that they operate are slightly different between the two.

You will need to read the AVR code, referring to the AVR data sheet, see what it is doing to configure and operate the peripheral device. Then refer to the corrresponding section of the PIC32 data sheet and Family guide and figure out which registers and bits need to be set to accomplish the same thing on the PIC32 device. There is no simple one-to-one translation from AVR to PIC32.

Also, note: The AVR data sheet contains all the relevant information on the peripherals. The PIC32 data sheets give an overview, but all of the details of the operation of the peripherals is in the appropriate section of the PIC32 Family Reference Guide.

Gene Apperson Digilent


GeneApperson

Wed, 17 Aug 2011 18:09:55 +0000

On further looking at the errors that you are getting, a lot of them refer to timers, output compares, and input captures. Unfortunately, these are the peripherals where there is the greatest divergence between the AVR and PIC32 devices.

In any case, however, the advice is the same. You need to understand what the AVR code is trying to accomplish using the peripheral device, and the figure out how to do the equivalent thing in the PIC32. It won't be as simple as translating register names and bit names from one to the other.

Gene Apperson Digilent


WestfW

Wed, 17 Aug 2011 21:00:45 +0000

You need to understand what the AVR code is trying to accomplish using the peripheral device, and the figure out how to do the equivalent thing in the PIC32. It won't be as simple as translating register names and bit names from one to the other.

You might be able to approach it from the other direction: understand how to talk to the TLC, and write an arduino-style library that DOESN'T use low-level register access, so that it works on both Arduino and ChipKit. (I don't know enough about the TLC to know if that's even possible. But the sort of "re-factoring" that carefully separates the architecture specific parts of a library from the general logic of the library is a generally useful thing to do.)


laelfrog

Fri, 19 Aug 2011 07:57:41 +0000

You are right, the Arduino TLC5940 library uses 2 timers and one interrupt that We'll have to hook up. Its definitely not just a patch up job.

It basically used FastMode PWM with 2 timers to handle a clock signal and a few cyclical signals

This article was helpful in trying to understand what is going on in the code. http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

The first timer effectively controlled 2 pins, XLAT and BLANK. BLANK is used to signal the beginning of the Grayscale PWM Cycle of the LEDs that the TLC5940 is controlling. BLANK is triggered every cycle, but XLAT was only fired when it was needed - Enabled by the COM1A1 bit.

XLAT is what latches the Grayscale Data into place and is only fired occasionally when new data is latched in.

Does the Pic32 Controller have timers that can manage 2 pins that each have their own OC registers? The cycles of XLAT and BLANK are sychronized but the XLAT signal is disabled most of the time. Is there some example code of something like this for the UNO32 or PIC32MX320F128?


GeneApperson

Fri, 19 Aug 2011 15:17:03 +0000

The output compares in the PIC32 aren't associated with timers the way they are in the AVR. Each output compare can be set to trigger from timer 2 or timer 3 . So, you can toggle up to 5 pins from the same timer.