Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Using Arduino / Programming Questions / Re: Help with optimizing code on: September 17, 2013, 06:09:01 pm
It's one of those small Nokia LCD screens.
I know... unusual, but they use 9-bit SPI smiley-sad
I would hate to change my hardware at this point.
32  Using Arduino / Programming Questions / Re: Help with optimizing code on: September 17, 2013, 05:42:49 pm
I did try the hardware SPI way back then, but this is a 9-bit SPI, so in order to make it work, I need to send the 1st bit manually and then shift the rest of the 8bit through hardware SPI.
In order to manually use MOSI and SCLK pins, I have to set SPCR=0, manipulate the pin status, sett SPCR=50 and shift the bits through hardware SPI, which at the end of the day, was takes just as long if not longer.
I'm going to scope the soft SPI when I get home.
33  Using Arduino / Programming Questions / Re: Help with optimizing code on: September 17, 2013, 04:57:42 pm
Thanks all for the help!!!
Unfortunately, I should have done my homework before I asked the question smiley-sad
I noticed after I edited the code that the bottleneck isn't really on the color calculation.
Although it helped a bit, it didn't help really substantially.
I did a quick comparison and it took 420ms to display 131x131 pixels with the original code and 391ms with Rob's optmized using byte size.
So, my bottleneck is really the SPI transmission.
I'm using soft SPI. So, how can I improve?
I did try hardware SPI some time ago and there was not much difference back then. Maybe I was doing something wrong back then too.
Here is the code I'm using to test:
Code:
#define BL0 cbi(PORTE,4);
#define BL1 sbi(PORTE,4);
#define CS0 cbi(PORTE,5);
#define CS1 sbi(PORTE,5);
#define CLK0 cbi(PORTG,5);
#define CLK1 sbi(PORTG,5);
#define SDA0 cbi(PORTE,3);
#define SDA1 sbi(PORTE,3);
#define RESET0 cbi(PORTH,3);
#define RESET1 sbi(PORTH,3);

#define sbi(port,bitnum)  port |= _BV(bitnum)
#define cbi(port,bitnum)  port &= ~(_BV(bitnum))

void setup()
{
  Serial.begin(57600);
  unsigned long start = millis();
  for (byte i=0;i<132;i++)
    for (byte j=0;j<132;j++)
      SendColor12BitOptimized(0xff);
  Serial.println(millis()-start);
  start = millis();
  for (byte i=0;i<132;i++)
    for (byte j=0;j<132;j++)
      SendColor12Bit(0xff);
  Serial.println(millis()-start);
 
}

void loop()
{
}

void SendData(byte data)
{
  CLK0;
  SDA1;
  CLK1;
  ShiftBits(data);
}

void SendCMD(byte data)
{
  CLK0;
  SDA0;
  CLK1;
  ShiftBits(data);
}

void ShiftBits(byte b)
{
  byte Bit;
 
  for (Bit = 0; Bit < 8; Bit++)
  {
    CLK0;
    if((b&0x80)>>7)
    {
      SDA1;
    }
    else
    {
      SDA0;
    }
    CLK1;
    b <<= 1;
  }
}

void SendColor12BitOptimized(byte color)
{
  byte RR = (color & 0xE0) >> 4;
  if (RR >= 8) RR++;
  byte GG = (color & 0x1C) << 3;
  if (GG >= 0x70) GG += 16;
  byte BB = (color & 0x03) * 5;
  SendData(RR);
  SendData(GG+BB);
}

void SendColor12Bit(byte color)
{
  int R=(color&0xE0)>>5;
  if (R>=4) R=((R*2)+1); else R=R<<1;
  int G=(color&0x1C)>>2;
  if (G>=4) G=((G*2)+1)<<4; else G=G<<5;
  int B=(color&0x03)*5;
  SendData(R);
  SendData(G+B);
}
34  Using Arduino / Programming Questions / Re: Help with optimizing code on: September 16, 2013, 07:58:35 pm
Or, you could multiply the R and G values by 2 (shift left 1), giving you possible values of 0, 2, 4, 6, 8, 10, 12, 14.

Then mutiply the G value by 5., giving you possible values of 0, 5, 10, 15.
This is actually what I am doing, if you look at the code I posted in the original code.
Except I'm doing one more check to be able to add 1 to get the 15 for R and G or the colors would not be correct with the result being 14.
If I separate into 3 tables, I would still have to apply the masks and shift right to get the pure value of each color, so the calculation would still be intense and I would only be trading the shift left and 1 comparison for a table lookup. I'll test and see if there is any improvement.
35  Using Arduino / Programming Questions / Re: Help with optimizing code on: September 16, 2013, 06:33:29 pm
I need to convert the colors to make it backward compatible with my old code/LCD screens.
My old LCD screens used 8bit color mode and the new ones use 12bit.
I guess table lookup would work.
It would consume 512bytes of RAM, right?
If I made the table PROGMEM, would I be taking a penalty in speed vs using RAM?
I am using a ATMega2560, so I do have a little bit of breathing on RAM, but would rather not use it if PROGMEM would give me the same results.
36  Using Arduino / Programming Questions / Help with optimizing code on: September 16, 2013, 04:00:06 pm
Hi guys,

I'd like to optimize this piece of code so it executes as fast as possible.
It basically converts a 8bit color into 12bit.
In 8bit, the RGB is as follow:
R = 3bit
G = 3 bit
B = 2 bit
And I'm upscaling it to 12bit:
R = 4bit
G = 4bit
B = 4bit
Here is the code:
Code:
int R=(color&0xE0)>>5;
if (R>=4) R=((R*2)+1); else R=R<<1;
int G=(color&0x1C)>>2;
if (G>=4) G=((G*2)+1)<<4; else G=G<<5;
int B=(color&0x03)*5;
How can I optimize this to work more efficiently and thus faster?

Thank you,
RI
37  Products / Arduino Due / Re: Arduino Due and ADK 2012 on: September 07, 2013, 03:51:42 pm
I think you are in the wrong thread.
This is for a Due board and not Mega.
Also, maybe you ought to start with blink code before you start trying to use Goodle ADK stuff.
38  Products / Arduino Due / Re: Arduino Due and ADK 2012 on: September 07, 2013, 12:15:35 pm
You must use native port
39  Products / Arduino Due / Keeping RTC time on: July 10, 2013, 12:10:13 pm
How do I keep the RTC time on Due?
Can i use CR1220 battery?
Which pins would I connect the battery?
40  Products / Arduino Due / Re: Reset the Arduino Due board using the watchdog on: July 09, 2013, 12:38:27 pm
Sorry for the premature question.
I found the answer inside the wdt.c:
Quote
* The WDT is running at reset with 16 seconds watchdog period (slow clock at 32.768 kHz)
 * and external reset generation enabled. The user must either disable it or
 * reprogram it to meet the application requires.
41  Products / Arduino Due / Re: Reset the Arduino Due board using the watchdog on: July 09, 2013, 12:12:40 pm
Does anyone know why the watchdog is disabled inside init() if it can only be written once?
42  Products / Arduino Due / Re: Arduino Due and ADK 2012 on: July 08, 2013, 01:25:10 pm
Ok, I just wanted to post my progress.
I was able to compile and upload the terminal code posted on the original thread to a Due board using IDE 1.5.2 using the programming port.
The original ADK2012 IDE required the native port.
After digging for a few days and comparing with the Google released ADK2012, I realized the problem is with the arduino reset code built-in on the libs to erase the flash when native port is used for programming (AKA open serial at 1200bps).
By having this code enabled all the time will disable the native port from ever being able to act as OTG port.
But the trick is that if this code is not enabled, you won't be able to erase flash and upload using native port on a single shot. You will need to press the ERASE button.
In my case, I'm never planning on using the native port for uploading code anyway, so my solution works out great for me.
My solution was to create a new board reference in the boards.txt file and remove the flags for the CDC serial on native port.

Code:

New_Board.name=My Own Board
New_Board.upload.tool=bossac
New_Board.upload.protocol=sam-ba
New_Board.upload.maximum_size=524288
New_Board.upload.use_1200bps_touch=true
New_Board.upload.wait_for_upload_port=false
New_Board.upload.native_usb=false
New_Board.build.mcu=cortex-m3
New_Board.build.f_cpu=84000000L
New_Board.build.core=arduino
New_Board.build.extra_flags=-D__SAM3X8E__ -mthumb
New_Board.build.ldscript=linker_scripts/gcc/flash.ld
New_Board.build.variant=arduino_due_x
New_Board.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a


And add an ifdef on the USBCore.cpp to disable the CDC code.

Code:
#ifdef USBCON

Original USBCore.cpp code goes inside the ifdef. I can't add or the post is too long and exceeds the maximum allowed length of forum, which is 9500 characters.

#endif // USBCON
43  Products / Arduino Due / 4pin debug header on: July 06, 2013, 08:53:59 pm
What kind of debugger can I use on that 4pin debug header?
Would it only work on AVR Studio?

Thanks,
RI
44  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 04, 2013, 12:37:26 am
>Is there such a thing as a CAN I/O expander chips?
Microchip MCP2502 CAN I/O Expander Family

http://ww1.microchip.com/downloads/en/devicedoc/21664d.pdf



Hope this helps,

Joachim
Have you used them yet?
I heard it's a pain to program them.
It seems to be a one shot deal and the dev kit has some issues burning it and you end up with bricked chips.
Just wanted to have anyone else's experience with them.
45  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 03, 2013, 12:42:09 pm
Is there such a thing as a CAN I/O expander chips?
One that would work similar to I2C I/O expanders?
Pages: 1 2 [3] 4 5 ... 10