2013年12月2日月曜日

XBEE : RECEIVER

XBEE RECEIVER BOARD

XBEE is connected to PIC and send the command to the other XBEE via USART.
IR-LED can output signal for controlling TV or other IR-controllable appliances and it is controlled by PWM.
Carrier is 40kHz so PWM frequency is set to that value and the duty ratio is 1:3. 


PCB is Arrived and Assembled

PCB arrived which I ordered on Nov.8th.

I only ordered 5pcs but arrived amount is 11pcs!
Trying samples were added to my order? Anyway I satisfied its quality. There are no pattern short and wrong drill position. Silk is not beautiful but there is no inconvenience.


Below figure shows my assembled results. Seemed to be working correctly.

In this time purchase, It needs 16 days to deliver from their shipment. From order it needs 3 weeks.

2013年11月9日土曜日

Apple keyboard with numeric key + Track pad

Apple keyboard with numeric key + Track pad


Apple keyboard with numeric key is a little bit large when using with track pad.
I made mistake that I should buy wireless compact one only for 20 dollar...

Before replacing it, I make track pad board for reducing space.

I cut acrylic board and bend it like below picture.

Then, the track pad can be put and the space can be reduced.

But, best for looking is using wireless one.


2013年11月8日金曜日

Wake up timer : circuit is fixed

Wake up timer : circuit is fixed

Now I have finished designing circuit and below is snapshot of its discrete one.


This wake up timer has below functions:

1. Light up
LED light is turned on step by step by PWM driving before wake up buzzer is ringing. 
The time to lighting up can be changed by setting. This function can let user easy wake up like sunrise.

2. Buzzer
Sound is generally changed from small sound to large one for comfortable wake up.  
Buzzer sound is changeable because IC for buzzer is PIC16F88.

3. TV control
XBEE is equipped. Very rich. Then, this board can send the command to its counterpart via USART. The other XBEE receives the command and send the IR signal for TV control such as powering up and making sound large. The IR signal of my TV is already analyzed.
In the near future, all of the house appliance controlled by IR can be under control of this board.

I have designed PCB board by eagle and it will be arrived in couple of weeks. Then I will start soldering...


2013年8月10日土曜日

Pic : RS232 communication

RS232 communication on PIC

I will make the remote controller device by using XBEE. Before that, PC and PIC communication is tested.


18f2320 is used.
RX/TX port are used and TRISCbits.RC7 is set to be input I/O and TRISCbits.RC6 is set to output one. Also TRISCbits.RC6 is set to high.
Please check below setting is set correctly.
• SPEN (RCSTA<7>) bit must be set (= 1)
• TRISC<7> bit must be set (= 1)
• TRISC<6> bit must be cleared (= 0)

Below program needs windows' hyper terminal input.
10MHz clock is multiplied by config. HSPLL so clock is 40MHz.
Then, baud rate is 115.2kHz. 
//////////////////////////////////
//main program
//////////////////////////////////
#include <p18f2320.h>
#include <i2c.h>
#include <usart.h>
#include "i2cLCD.h"
#include "wait.h"

#pragma config OSC=HSPLL, FSCM=OFF, IESO=OFF, PWRT=ON
#pragma config BOR=ON, BORV=27, WDT=OFF, WDTPS=1024
#pragma config MCLRE=ON, PBAD=DIG, CCP2MX=C1
#pragma config STVR=OFF, LVP=OFF, DEBUG=OFF
#pragma config CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF
#pragma config CPD=OFF, WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF
#pragma config WRTB=OFF, WRTC=OFF, WRTD=OFF, EBTR0=OFF
#pragma config EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF

void main(void)
{
char test[]="AQM0802A";
char inputFromPC[] = "From PC";
char inputMsg[]="\r\nInput 5 characteristic= ";
char bufLcd[10]={0,0,0,0,0,0,0,0,0,0};

//I2C initialization
TRISC = 0x18;
SSPADD = 24; //MCLK40MHz / (4*(SSPAD+1)) = 400khz
  SSPCON1 = 0b00101000;

wait_ms(100);
lcdIni();

lcdCommand(LCD_1ST_LINE);
lcdPrintSting(test);

wait_ms(200);
lcdCommand(LCD_CLEAR);

//USART
TRISC |= 0x80;
LATC = 0x40; 
RCSTAbits.SPEN=1;
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX & USART_BRGH_HIGH,21);

while(1)
{
putsUSART(inputMsg);
getsUSART(bufLcd,5);
lcdCommand(LCD_CLEAR);
wait_ms(2);
lcdCommand(LCD_1ST_LINE);
lcdPrintSting(inputFromPC);
lcdCommand(LCD_2ND_LINE);
lcdPrintSting(bufLcd);
}
}

Pic : LCD AQM0802A driving

Driving AQM0802A LCD

I have bought AQM0802A which can be driven by the I2C bus.
Driving voltage is 3.3V so PIC is also driven by 3.3V for connecting by I2C.



Below is the example code of driving the LCD.
This ic has the function of continuous sending, but below code is only sending each byte every time. 

Sending each byte needs slave address, control byte and data byte.
By setting control byte, clear, changing cursor and etc can be implemented like SD1602 display.
This ic only needs 2 wire from Pic so we can use lots of port comparing with SD1602.

///////////////////
i2cLCD.h
///////////////////
#ifndef I2C_FUNCTION
#define I2C_FUNCTION

#define SLV_ADDR 0x7C
#define LCD_CLEAR 0x01
#define LCD_1ST_LINE 0x80
#define LCD_2ND_LINE 0xC0

int lcdCommand(char cmd);
int lcdIni(void);
int lcdByteWrite(unsigned char cmd, unsigned char data);
int lcdPrintSting(char* str);

#endif

///////////////////
i2c functions
///////////////////
#include <p18f2320.h>
#include <delays.h>
#include <i2c.h>
#include "i2cLCD.h"
#include "wait.h"

int lcdPrintSting(char* str)
{
char byteRsOn=0x40;
//Send buffer data
while(*str!=0x00)
{
lcdByteWrite(byteRsOn, *str);
str++;
}

return 0;
}

int lcdCommand(char cmd)
{
lcdByteWrite(0x00, cmd);
return 0;
}

int lcdIni(void)
{
OpenI2C(MASTER,SLEW_OFF);
//Function set
lcdByteWrite(0x00, 0x38);
wait_ms(1);

//Function set, IS=1
lcdByteWrite(0x00, 0x39);
wait_ms(1);
//Internal osc freq. setting
lcdByteWrite(0x00, 0x14);
wait_ms(1);

//Contrast set
lcdByteWrite(0x00, 0x70);
wait_ms(1);

//Power/ICON/Contrast control
lcdByteWrite(0x00, 0x56);
wait_ms(1);

//Follower control
lcdByteWrite(0x00, 0x6C);
wait_ms(300);

//Function set
lcdByteWrite(0x00, 0x38);
wait_ms(1);

//Dispaly on/off control
lcdByteWrite(0x00, 0x0C);
wait_ms(1);

//Clear dispaly
lcdByteWrite(0x00, 0x01);
wait_ms(2);

    return 0;
}


int lcdByteWrite(unsigned char cmd, unsigned char data)
{
//Start Condition
    IdleI2C();
    StartI2C();
    while(SSPCON2bits.SEN){;}
        
//Write Slave Address wtih Write mode
    if(WriteI2C(SLV_ADDR)<0){return -1;}
IdleI2C();
    //Send control byte
    if(WriteI2C(cmd)<0){return -2;}
IdleI2C();
//Write data
if(WriteI2C(data)<0){return -3;}
//Send Stop
IdleI2C();
    StopI2C();
while(SSPCON2bits.PEN);
Delay10TCYx(4);
    
return 0;

}


/////////////////////////////////
//main: 10MHz external OSC is used
/////////////////////////////////
void main(void)
{
char test[]="AQM0802A";

  //I2C initialization
TRISC = 0x18;
SSPADD = 24; //MCLK40MHz / (4*(SSPAD+1)) = 400khz
  SSPCON1 = 0b00101000;
wait_ms(100);
lcdIni();

lcdCommand(LCD_1ST_LINE);
lcdPrintSting(test);
lcdCommand(LCD_2ND_LINE);
lcdPrintSting(test);
while(1)
{

}

2013年7月19日金曜日

Sony "Bravia" Remote controller

Making remote controller

My TV is Sony's Bravia and I'd like to control my TV in my program.
My final target is to combine the wake up timer and remote controller. Special wake up timer will let me wake up with setting TV my favorite program or setting air conditioner with set of comfort temperature. 

The Tektronix TBS1022 help me to understand the protocol of IR signals of controller.

Protocol

Overall

IR signals consists of "Header", "Data" and "Address" area.










Size of "Data" is 8 bit and that of "Address" is 4 bit.

Each data cycle

Standard cycle of signal is 600usec(T).
"Header" consists of high condition for 4T period and low condition for 1T period.
i.e, "Header" is 2,400usec high state and 600usec low state.

Each bit data is presented by combination of high condition time and low condition time.

If bit is high, the signal consists of 2T high and 1T low. Please see below "Data 1".
If bit is low, the signal consists of 1T high and 1T low. Please see below "Data 0".

i.e, "Data 1" is 1,200usec high state and 600usec low state.
"Data 0" is 600usec high state and 600usec low state.













PWM waveform is used for above control and its frequency is 40kHz.


Repeat signal 4 times

Above protocol is send 4 time with specific interval.
Like below figure, the 45.0msec interval time is necessary for each command.











Command

I don't care which side is MSB-side. So maybe my understanding is not correct.
So the code is just reference data.
Please be apply my code to below sample program.

Address is 0x00 so only data code is written in below.
Volume-up : 0xC9
Volume-down : 0x49
Channel 1 : 0x01
Channel 2 : 0x08


In my program, 0x0C90 is set for "Volume-up".

Program

Below is my program for test above protocol. The wait time is a little bit different from above ideal specific. 

#include <p18f2320.h>
#include <delays.h>
#include "wait.h"

#pragma config OSC=HSPLL, FSCM=OFF, IESO=OFF, PWRT=ON
#pragma config BOR=ON, BORV=45, WDT=OFF, WDTPS=1024
#pragma config MCLRE=ON, PBAD=DIG, CCP2MX=C1
#pragma config STVR=OFF, LVP=OFF, DEBUG=OFF
#pragma config CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF
#pragma config CPD=OFF, WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF
#pragma config WRTB=OFF, WRTC=OFF, WRTD=OFF, EBTR0=OFF
#pragma config EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF

//10MHz OSC and OSC is set to HSPLL
#define MCLK 40
#define PERIOD 24

int sendData(unsigned int data);
int ledOn(int cycle);
int dataLow(void);
int dataHigh(void);
int headerIR(void);

void main(void)
{
  //PORT A initial setting
  ADCON1 &= 0x0F;
TRISA = 0x00;
  LATA = 0x00;

wait_ms(MCLK, 500);
while(1)
{
sendData(0x0490);
wait_ms(MCLK, 10);
}
}

int ledOn(int cycle)
{
int i;
for(i=0; i<cycle;i++)
{
LATAbits.LATA0 |= 0x01;
Delay100TCYx(1);
Delay10TCYx(2);
Delay1TCY();
Delay1TCY();
Delay1TCY();
LATAbits.LATA0 &= 0xFE;
Delay100TCYx(1);
//Delay10TCYx(2);
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
}
return 0;
}


int headerIR(void)
{
//PWM on
int i;
for(i=0; i<96; i++)
{
LATAbits.LATA0 |= 0x01;
Delay100TCYx(1);
Delay10TCYx(2);
Delay1TCY();
Delay1TCY();
Delay1TCY();
LATAbits.LATA0 &= 0xFE;
Delay100TCYx(1);
//Delay10TCYx(2);
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
}

//off 1T
LATAbits.LATA0 &= 0xFE;
Delay1KTCYx(6);
return 0;
}

int dataLow(void)
{
//on 1T
ledOn(PERIOD);

//off 1T
LATAbits.LATA0 &= 0xFE;
Delay1KTCYx(6);
}

int dataHigh(void)
{
//on 2T
ledOn(PERIOD * 2);
//off 1T
LATAbits.LATA0 &= 0xFE;
Delay1KTCYx(6);
}

int sendData(unsigned int data)
{
int cnt;
int i, j;
unsigned int restTime;

for(j=0; j<4; j++)
{
cnt = 0;
restTime = 450; //45usec / 100, to make caluculation decrease
//header
headerIR();
cnt += 5; //3000usec is used for header data

//data
for(i=11;i>=0;i--)
{
if( ((data >> i) &0x01) == 1)
{
dataHigh();
cnt += 3;
}
else
{
dataLow();
cnt += 2;
}
}

//wait
restTime -= cnt * 6;
Delay10KTCYx(restTime / 10);
Delay1KTCYx(restTime % 10);
}
}




2013年7月17日水曜日

Tektronix Oscilloscope

Tektronix Oscilloscope

I got Tektronix TBS1022 that is just only 500 hundred dollar with 5 year guarantee. Now the Japanese yen become weak so there is a possibility of changing the sales price in Japan. Actually apple's iPod and iPad become a little bit expensive... Before changing the price, I decided to buy.

Band width is only 25MHz but it is enough for me to analyze my boards.




















In the near future, I'm going to make remote controller of my TV by using PIC by analyzing its signals.

2013年4月3日水曜日

two dimensional array on iOS

Making two dimensional array on iOS.

By using NSMutableArray class, changeable   two dimensional array can be made by like following.

notice: I don't guarantee any issues caused by below source

- (NSMutableArray*)twoDimensionalArray:(int)width height:(int)height
{
    NSMutableArray* folder=[NSMutableArray array];
    for(int i=0;i<height;i++)
    {
        [folder addObject:[[NSMutableArray alloc] initWithCapacity:width]];
    }
    
    return folder;
}

- (void)exampleFunc
{
    NSMutableArray* array=[NSMutableArray array];
    array=[self twoDimensionalArray:2 height:2];
    
    int k=1;
    for(int j=0;j<2;j++)
    {
        for(int i=0; i<2;i++)
        {
            [[array objectAtIndex:j] addObject:[NSNumber numberWithInt:k]];
            k++;
        }
    }
    
    for(int j=0;j<2;j++)
    {
        for(int i=0; i<2;i++)
        {
            NSLog(@"val:%d",[[[array objectAtIndex:j] objectAtIndex:i] intValue]);
        }
    }
}