Adapting code! Works on AVR, need help with XMOS! :)

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
CaptainObvious
Member
Posts: 14
Joined: Wed Dec 30, 2009 12:24 pm

Adapting code! Works on AVR, need help with XMOS! :)

Postby CaptainObvious » Fri Jan 01, 2010 8:52 pm

Long time listener, first time caller!~ :lol:

Well I've been playing with AVR micros for a while now, Arduino's in particular. I'm fairly familiar, but still by all means a newb!

I have a SPI color LCD, the 6610 from Gravitech:
http://store.gravitech.us/13secogrlcd.html
I'm able to get it to work in 8 bit SPI(I think it's 8bit?) on the Arduino. The example code is provided at the bottom of the link above, here's the library that was made with the sketch:
http://freetexthost.com/f4g26r1eyx

The 6610's come with either the Epson S1D15G00 or the NXP PCF8833 controller.. I've got the Epson version, and there's an example with the NXP controller.. sets me in the right direction, but still lost! :) Now I could use some help interfacing the Epson version! Bianco(http://www.xcore.com/users/Bianco) made a post where he was using the LCD to play a video! (I was hoping for a picture.. but a video?! time for some all nighters!) This is what really makes me want to get it to work with my controller.

Here's the link to the datasheet of the Controller my LCD is using if it will help any:
http://gravitech.us/MicroResearch/Other ... REV1_0.pdf

I edited some of the commands, and the Initializing procedure.. but I'm unable to get anything to show up on the LCD. I'm using a different board as well, the XK1 rather than the XC1? I kept the pin names the same, and I have jumper wires running from the pins to the LCD. (I hope they're correct, not too familiar with how XMOS interprets pins, but from how they're labeled in the code, they're correct)

// Ports connected to the LCD (all 1-bit ports)
XK PINS:
#define N6100_LCD_RESET XS1_PORT_1A // LCD reset line pin XD0
#define N6100_LCD_SEL XS1_PORT_1B // LCD chip select pin XD1
#define N6100_LCD_CLK XS1_PORT_1C // sclk pin XD10
#define N6100_LCD_DAT XS1_PORT_1D // mosi pin XD11


I'm also afraid this *could* be a problem? I'm borrowing all of the SPI code from the sketch, so that could be it too.. but this in particular:
// SPI settings
#define N6100_LCD_SPI_SPEED 1000000 // SPI speed in Hertz
#define N6100_LCD_SPI_PERIOD (100000000/N6100_LCD_SPI_SPEED) // period in 10ns granularity
#define N6100_LCD_SPI_HALF_PERIOD (N6100_LCD_SPI_PERIOD/2) // half of a period in 10ns granularity
#define USE_EXP_SPI 0 // a faster SPI routine which exceeds PCF8833 specs

The Epson controller needs at LEAST 50ns it says in the Tutorial, I used the Waveform Visualizer (I think that's the name) and it was showing that the pins were taking longer than 250 ms.. so I'm guessing I'm doing something wrong. (I could have been using the Waveform Visualizer wrong, but I went through the tutorial a few times to make sure)
(here's the quote from the tutorial, if it helps any?)
SPI baud rate set to MCK/2 = 48054841/3 = 16018280 baud
(period = 62 nsec, OK since 50 nsec period is min for S1D15G00)


Okay.. uh, hope I covered everything.. still getting used to the XMOS environment, let alone the XK-1 pinout, so bare with me! I hope I wasn't too confusing.. I was a bit confused myself, not sure where to start.. or what to ask exactly. :D

Thanks for actually *trying* to read through this!
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Fri Jan 01, 2010 9:27 pm

As for pins:

out port N6100_LCD_RESET = XS1_PORT_1A; // LCD reset line pin XD0
out port N6100_LCD_SEL = XS1_PORT_1B; // LCD chip select pin XD1
out port N6100_LCD_CLK = XS1_PORT_1C; // sclk pin XD10
out port N6100_LCD_DAT = XS1_PORT_1D; // mosi pin XD11

As for SPI your out of luck since you have to create a bitbanged SPI or define a pin as the clock and set a data pin to it.

Anyway take a look here the LCD so similar you can copy most the code heh:
http://www.xcore.com/projects/nokia-610 ... controller

Also you paid too much...
http://cgi.ebay.com/Nokia-6100-6610-Col ... 2556d05cd0

As you can see i did code for that LCD and sold it to them heh... but my site is down... The code was for a PIC and ARM i think tho....
User avatar
CaptainObvious
Member
Posts: 14
Joined: Wed Dec 30, 2009 12:24 pm

Postby CaptainObvious » Sat Jan 02, 2010 2:31 am

Hey, thanks for the reply!:)

As for over paying, no way! The LCD I have has a built in Logic Level Converter, also a DC to DC boost converter. Can be powered from 3.3v or 5v, and can also take logic levels 3.3v or 5v! (also, the backlight is normally 7v, you can power that from 3.3v or 5v as well.) But if I would have known.. I would have paid the extra $10 for this OLED LCD, which has a built in SD-card and uses UART control.
https://www.sparkfun.com/commerce/produ ... ts_id=8538

But anyways! Regardless. Onto the code! Or trying anyways. :P Keep in mind, the controller he's using is different from mine, so it could very much be a simple code problem.

I did download the code he provided, actually, every piece of my code is built off what he has. The only thing I've changed is the Commands and the Initialization routine.

So, closer to the bottom on my first post, there are defines for the LCD_SPI_SPEED.. and I also have the SPI_TRANSMIT commands, are those being bitbanged?
Here's the full code used for the SPI_transmit, not sure how different this is, if at all from the Epson controller.. lol not a big SPI fan. I know for sure he was over clocking the SPI, or at least he said he was, which is how he was able to play video with such a good framerate/resolution.. which I think may be resulting in not working right on my LCD.

I've tried the Initialization code I found in the walk through by James P Lynch, and also the code that *works* on the AVR. (both without success)

Now, for the Pins being used.. I was under the impression that it IS being bit-banged with those pins? The only reason I figured was because in the XK1 hardware page shows the SPI ports being used by the External Flash.. doesn't look like they're brought out to be used. (not on any of the headers)

Code: Select all

// *************************************************************************************************
// n6100_lcd_spi_transmit(int type, unsigned char indata)
//
// Transfer 9 bits to the LCD controller using SPI.
// We do not receive anything as the MISO pin of the LCD controller
// is not brought out in the Nokia 6100 LCD.
// Transfer is MSB first, the first bit transferred indicates if the succeeding byte
// is a command or data byte.
//
// SPI settings: 9 bits
//               CPOL=1 (clk idle high)
//               CPHA=1 (data captured at rising edge)
//
// Wave form:
//     ___                                                                          __
//        \                                                                        / 
// ssel    \______________________________________________________________________/ idle high
//    ___       __      __      __      __      __      __      __      __      ______ 
//       \     /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /         
// clk    \___/    \__/    \__/    \__/    \__/    \__/    \__/    \__/    \__/     idle high
//          ______  ______  ______  ______  ______  ______  ______  ______  ______
//         / D/C  \/  7   \/  6   \/  5   \/  4   \/  3   \/  2   \/  1   \/  0   \
// data    \______/\______/\______/\______/\______/\______/\______/\______/\______/ idle dont't care
//
//
// Inputs: 	type = command or data byte (N6100_LCD_CMD or N6100_LCD_DATA)
//          indata = byte to transfer
// 			 
// Returns: nothing
//
// Author: Bianco Zandbergen November 28, 2009
// *************************************************************************************************
#if USE_EXP_SPI == 0
void n6100_lcd_spi_transmit(int type, unsigned int indata)
{
	
	unsigned time;
	int i;
	unsigned int data;
		
	// select lcd
	// clock must be low before selecting lcd
	lcd_clk <: 0;
	lcd_sel <: 0;
	
	// change bit endianes because we have to transfer MSB first.
	// incoming data:
	// xxxxxxxx xxxxxxxx xxxxxxxx 76543210
	// after byterev:
	// 76543210 xxxxxxxx xxxxxxxx xxxxxxxx
	// after bitrev:
	// xxxxxxxx xxxxxxxx xxxxxxxx 01234567
	// after that we shift it 1 bit to the left
	// and push the bit indicating a command or data byte
	// to the front
	data = bitrev(byterev(indata));     
	data <<= 1;
	data |= type;
	
	/* safe current time */
	t1 :> time;
	
	#pragma loop unroll
	for (i = 0; i < 9; i++) {
		lcd_dat <: >> data;					// put data bit on line, shift data 1 to the right
		lcd_clk <: 0;						// clock low
		
		time += N6100_LCD_SPI_HALF_PERIOD;	// wait half period
		t1 when timerafter(time) :> void;
		
		lcd_clk <: 1;						// clock high, data will be read by lcd controller
		
		time += N6100_LCD_SPI_HALF_PERIOD;	// wait half period
		t1 when timerafter(time) :> void;
	}
	
	lcd_clk <: 1;
	lcd_sel <: 1;

	asm("nop;nop;"); // just to make sure ssel is at least 40ns high, in practice this might be removed
}

#else

void n6100_lcd_spi_transmit(int type, unsigned int data)
{
	
	int i;
		
	lcd_clk <: 0;
	lcd_sel <: 0;
	
	data = bitrev(byterev(data));     
	data <<= 1;
	data |= type;
		
	#pragma loop unroll
	for (i = 0; i < 9; i++) {
		
		lcd_dat <: >> data;
		lcd_clk <: 0;	
		lcd_clk <: 1;	
	}
	
	lcd_clk <: 1;
	lcd_sel <: 1;
}
#endif
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Sat Jan 02, 2010 3:11 am

how is the USE_EXP_SPI set in your code?

Ensure that it is a 0 to not overclock i think... i have to redownload his code
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Sat Jan 02, 2010 3:32 am

Ok i did a wave trace and it seems to be 51ns from Rise to Fall:

2009.23us to 2009.74us

So maybe if you slow it down a bit.... try this:

Code: Select all

#define N6100_LCD_SPI_SPEED	900000// SPI speed in Hertz
or something... im not the math type heh
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Sat Jan 02, 2010 3:40 am

Look at this...

Code: Select all

#define N6100_LCD_SPI_SPEED			1000000 // SPI speed in Hertz
#define N6100_LCD_SPI_PERIOD 		(100000000/N6100_LCD_SPI_SPEED) // period in 10ns granularity		
#define N6100_LCD_SPI_HALF_PERIOD 	(N6100_LCD_SPI_PERIOD/2) // half of a period in 10ns granularity
if this produces a half period or Rise to Fall of 50ns then reverse it for 63ns like:

2 * x = SPI speed....

2 * 63ns = 126...
100,000,000/126 = 793650.7936507937 aka 793651

so... (if im right)

Code: Select all

#define N6100_LCD_SPI_SPEED			793651// SPI speed in Hertz
The above line should clock at 63ns

Just tested and i get 62ns as the RISE to FALL of the clock. which is perfect almost... heh
User avatar
CaptainObvious
Member
Posts: 14
Joined: Wed Dec 30, 2009 12:24 pm

Postby CaptainObvious » Sat Jan 02, 2010 3:57 am

Okay, I see where you're coming from.. that makes sense!

I've tried the USE_EXP_SPI with both 0 and 1. So I'm starting to think maybe it's in the Initialization routine?

I tried the different #define speeds, without any difference.

I tested it again on my Arduino just to make sure I haven't damaged it.. still works fine. I did test the ports I'm used, and it *seems* like they're plugged in right. (doesn't mean I'm using the right kind of port, still trying to grasp the use of the multi-bit port stuff)

I'm looking for any kind of justification it's working.. the Arduino code I'm using also Clears the screen after it initializes, which makes the screen BLACK. (greyER-black) And if it's NOT cleared (just after initializing, actually, even without initializing, it's PITCH black) If it initialized right, it would at least print messed up pixel colors. But only getting the pitch black screen.


I'm starting to think it's a simple user error that could have been diverted.. but I've gone through the code multiple times and not understanding where it could be off. (other than the XMOS parts, which I don't understand too well) I *DID* only change the Initialization.. so maybe I need to change more? Like how data is being sent to the controller? Not too sure!


Thanks for taking the time to read through this at least this much! (I'm confusing even myself just trying to read it, lol :))

EDIT:
One thing I should also mention, he used the XC-1 board.. and I'm using the XK-1. So I had to change the .XN file.. I just opened a New Project for the Button project.. and just used the XK1.XN file from that, copied it over to this LCD setup.
I've read about the .XN files a little bit.. but I don't want to try grasp too many things at once.. I'm too easily confused. :) So I'm wondering if I need to change any settings in the .XN file to cope with the code that was previously used with a different board and .XN file?
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Sat Jan 02, 2010 4:02 am

ive done the Phillips LCD before so ima take a look at the data sheet for epson and phillips can compare and see if we can get this working ok...

can you post your init code... also after init its a good idea to clear the screen with white to determine if its working ok

EDIT:
The XN file has no special nodes in it from what i can see so i doubt its the issue... but im simulating it now to ensure the pins are altered correctly

heh you could actually leave it at 1000000 hz since its making a 500ns clock:

Code: Select all

#define N6100_LCD_SPI_SPEED         1000000 // SPI speed in Hertz
The minimum is 50ns...
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm

Postby AtomSoft » Sat Jan 02, 2010 4:35 am

If possible zip your entire project using the export command from menu and post it here. Im sure i can have it working...

Silly question.... did you change all the commands to match those in the EPSON datasheet?
User avatar
CaptainObvious
Member
Posts: 14
Joined: Wed Dec 30, 2009 12:24 pm

Postby CaptainObvious » Sat Jan 02, 2010 5:11 am

Silly question.... did you change all the commands to match those in the EPSON datasheet?
Indeed, I also changed the initialization routine since they were quite a bit different.

Okay, just zipped a file up. Inside the Documents folder, is the .PDFs I'm using as a reference, the Epson datasheet, a super-long walk through on the 6610 LCD's (both controllers), and the LCD "manual" from Gravitech, shows the pin out of the LCD and such.
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: No registered users and 3 guests