DSPRelated.com
Forums

C6713 EMIF INTERFACING HELP REQUIRED

Started by samz...@hotmail.com July 3, 2010
Hi
I am new to DSP kit and we are implementing our final year degree project on it. I am facing some of very basic issues.

C6713 is little endain by default. We have to interface emif data pins with AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data pins on the emif connector. But the confusion is that which pins should be interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.

Secondly the 3 LEDs taht blink when the DSK is turned on, are no more blinkly, they just stay off. I think because of this our project does not build properly. Is there any way it can be fixed??

Help will be highly appreciated
Regards
samz

_____________________________________
samz,

On Sat, Jul 3, 2010 at 9:13 AM, wrote:

> Hi
> I am new to DSP kit and we are implementing our final year degree project
> on it. I am facing some of very basic issues.
>
> C6713 is little endain by default. We have to interface emif data pins with
> AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data pins
> on the emif connector. But the confusion is that which pins should be
> interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.
>

I would address this based on "where you want the bits to end up" to
simplify processing. I would consider connecting the MSB to bit 15 in order
to manipulate the data as a signed 16 bit number [I have no idea about your
app - this is something that I have done in the past]. The other bits would
go down from there and you could force the unused bits to 0.

>
> Secondly the 3 LEDs taht blink when the DSK is turned on, are no more
> blinkly, they just stay off. I think because of this our project does not
> build properly. Is there any way it can be fixed??
>

The three LEDs normally toggle based on the execution of a POST that is in
the flash. You might try powering up the board with nothing connected to see
if it will execute - the emulation logic may be preventing the execution.

mikedunn

>
> Help will be highly appreciated
> Regards
> samz
>
>

--
www.dsprelated.com/blogs-1/nf/Mike_Dunn.php
HI
First of all thanks alot for replying.

If the adc i am using is 12 bit, wont i be needing 12 bits only?? meaning 12 data pins on the emif connector.
At the moment i am connecting data pin 0 to data pin 11. However i am not sure if it is correct, i am new to the DSK, and am very confused about which pin is the MSB or LSB.

I saw a case study about it too, in that there were also 16 bits going from the ADC to the daughtercard however i could not understand how can there be 16 lines??

This is the code i am implementing at the moment. I need to generate a square pulse using the DSK.

#include "Maycfg.h"
#include "dsk6713.h"
#include "target.h"
#include "stdio.h"
#include "csl.h"
#include "csl_cache.h"

#include "csl_timer.h"
#include "csl_irq.h"
#include "csl_pll.h"
#include
#include
#include

#define INTDSK_CE2 0xA0000000
#define BUFF_SZ 1000

Uint32 ad_buffer[BUFF_SZ];

static Uint32 TimerEventId1;
static Uint32 analogue_in = 0;
static Uint32 count = 0;

//FILE *fp_bs;
//FILE *fp_pw;
//FILE *fp_ab;
//FILE *fopen();
//char buffer_sz[10] ;
//char pulse_width[10] ;
int q=0;
GPIO_Handle myGPIO_handle;
GPIO_Config MyConfig = { 0x00000000, /* gpgc */

0x00000000, // gpen --

0x00000000, // gdir -

0x00000000, /* gpval */

0x00000000, /* gphm all interrupts disabled for io pins */

0x00000000, /* gplm all interrupts to cpu or edma disabled */

0x00000000 /* gppol -- default state */

};
void timer_isr();
void startpll(){

// Set main multiplier/divisor
PLL_RSET(PLLM, 9); // 50MHz x 9 = 450MHz
PLL_RSET(PLLDIV0, PLL_PLLDIV0_RMK(1, 0)); // 450MHz / 1 = 450MHz
PLL_RSET(OSCDIV1, PLL_OSCDIV1_RMK(1, 4)); // 50MHz / 5 = 10Mhz
// Set DSP clock
PLL_RSET(PLLDIV1, PLL_PLLDIV1_RMK(1,1)); // 450MHz / 2 = 225MHz
plldelay(20);
PLL_RSET(PLLDIV2, PLL_PLLDIV2_RMK(1, 3)); // 450MHz / 4 = 112.5MHz
plldelay(20);
// Set EMIF clock
PLL_RSET(PLLDIV3, PLL_PLLDIV3_RMK(1, 4)); // 450MHz / 9 = 50MHz 90MHz
plldelay(20);
LOG_printf (&trace, "end of pll");
return;}

void main(){

volatile static int j;
CSL_init();

/*fp_bs=fopen("buffersize.txt","r");
fgets(buffer_sz,10,fp_bs);
fclose(fp_bs);
fp_pw=fopen("pulsewidth.txt","r");
fgets(pulse_width,10,fp_pw);
fclose(fp_pw);
freopen("tracevalues.txt","w",stdout);
printf("%s \n",buffer_sz);
printf("%s \n",pulse_width);*/

myGPIO_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );

GPIO_config(myGPIO_handle , &MyConfig );

//GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);

GPIO_pinDirection(myGPIO_handle,GPIO_PIN4, GPIO_OUTPUT);

startpll();
EMIF_config(&emifCfg0);
IRQ_nmiEnable();
IRQ_globalEnable();

for (j=0; j<=BUFF_SZ; j++)
{ad_buffer[j]=0;
}

LOG_printf (&trace, "block cleared");

TimerEventId1 = TIMER_getEventId (hTimer1);
IRQ_enable (TimerEventId1);
TIMER_start (hTimer1);

return;
}

void timer_isr ()

{ int p=0;

LOG_printf (&trace, "isr");
analogue_in = *(unsigned volatile int *) INTDSK_CE2;
ad_buffer[count]=analogue_in & 1023;//2147483648;//1023;
if(count>100 && count <150)

{GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);
GPIO_pinWrite(myGPIO_handle,GPIO_PIN4,0);
GPIO_pinDisable (myGPIO_handle,GPIO_PIN4); }

count=count+1;

if (count=00)

//{for (p=0;p<1000;p++)
//printf("%d \n",ad_buffer[p]);
printf("Th");
return;

}

Your help will be greatly appreciated
Regards
samz

Hi
>I am new to DSP kit and we are implementing our final year degree project on it. I am facing some of very basic issues.
>
>C6713 is little endain by default. We have to interface emif data pins with AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data pins on the emif connector. But the confusion is that which pins should be interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.
>
>Secondly the 3 LEDs taht blink when the DSK is turned on, are no more blinkly, they just stay off. I think because of this our project does not build properly. Is there any way it can be fixed??
>
>Help will be highly appreciated
>Regards
>samz
>
>_____________________________________

_____________________________________
samz,

Where do I start?

Well, for starters, this code will not output a square wave.

The timer 1 interrupt has been enabled and the timer started, but the registers
of the timer 1 peripheral have not been setup.

The desired pulse width has been read into the program, but not used.

The desired buffer size has been read into the program but not used.

All output is being performed via 'printf()'.
Including during the execution of an interrupt handler.
That is a no-no.

The Log_printf() function queues the output and is a much better choice.

However, I doubt that even Log_printf() can keep up with the rate of output
requested.

the file tracevalues is opened for output, but never written to.

the timer 1 interrupt handler writes a 0 to GPIO pin 4, then disables the pin.
Disabling the GPIO pin causes it to be set to the high impedance state, not to
keep its' current output level.

-----------
The timer 1 peripheral needs to be setup AFTER reading in the pulse interval.
At each timer 1 interrupt event, the output to the GPIO pin 4 needs to be
toggled, not momentarily set to 0.

If it were me, I would start with fixed values of the pulse width and only add
the ability to read in the desired interval after everything else works.

*I* would eliminate all those printf statements as they will cause problems due
to the way printf() is implemented.

Stepping through the code with the CCS debugger and placing breakpoints at
critical areas, like the entry to the timer 1 interrupt event handler function
will make it much easier to debug.

BTW:
I would setup the timer1 peripheral to not continue counting when the emulator
is in 'halt' mode.
R. Williams

---------- Original Message -----------
From: s...@hotmail.com
To: c...
Sent: Sun, 04 Jul 2010 15:04:51 -0400
Subject: [c6x] Re: C6713 EMIF INTERFACING HELP REQUIRED

> HI
> First of all thanks alot for replying.
>
> If the adc i am using is 12 bit, wont i be needing 12 bits only??
> meaning 12 data pins on the emif connector. At the moment i am
> connecting data pin 0 to data pin 11. However i am not sure if it is
> correct, i am new to the DSK, and am very confused about which pin is
> the MSB or LSB.
>
> I saw a case study about it too, in that there were also 16 bits going
> from the ADC to the daughtercard however i could not understand how
> can there be 16 lines??
>
> This is the code i am implementing at the moment. I need to generate a
> square pulse using the DSK.
>
> #include "Maycfg.h"
> #include "dsk6713.h"
> #include "target.h"
> #include "stdio.h"
> #include "csl.h"
> #include "csl_cache.h"
>
> #include "csl_timer.h"
> #include "csl_irq.h"
> #include "csl_pll.h"
> #include
> #include
> #include #define INTDSK_CE2 0xA0000000
> #define BUFF_SZ 1000
>
> Uint32 ad_buffer[BUFF_SZ];
>
> static Uint32 TimerEventId1;
> static Uint32 analogue_in = 0;
> static Uint32 count = 0;
>
> //FILE *fp_bs;
> //FILE *fp_pw;
> //FILE *fp_ab;
> //FILE *fopen();
> //char buffer_sz[10] ;
> //char pulse_width[10] ;
> int q=0;
>
> GPIO_Handle myGPIO_handle;
> GPIO_Config MyConfig = { 0x00000000, /* gpgc */
>
> 0x00000000, // gpen --
>
> 0x00000000, // gdir -
>
> 0x00000000, /* gpval */
>
> 0x00000000, /* gphm all interrupts disabled for io pins */
>
> 0x00000000, /* gplm all interrupts to cpu or edma disabled */
>
> 0x00000000 /* gppol -- default state */
>
> };
>
> void timer_isr();
> void startpll(){
>
> // Set main multiplier/divisor
> PLL_RSET(PLLM, 9); // 50MHz x 9 = 450MHz
> PLL_RSET(PLLDIV0, PLL_PLLDIV0_RMK(1, 0)); // 450MHz / 1 = 450MHz
> PLL_RSET(OSCDIV1, PLL_OSCDIV1_RMK(1, 4)); // 50MHz / 5 = 10Mhz
> // Set DSP clock
> PLL_RSET(PLLDIV1, PLL_PLLDIV1_RMK(1,1)); // 450MHz / 2 = 225MHz
> plldelay(20);
> PLL_RSET(PLLDIV2, PLL_PLLDIV2_RMK(1, 3)); // 450MHz / 4 = 112.5MHz
> plldelay(20);
> // Set EMIF clock
> PLL_RSET(PLLDIV3, PLL_PLLDIV3_RMK(1, 4)); // 450MHz / 9 = 50MHz 90MHz
> plldelay(20);
> LOG_printf (&trace, "end of pll");
> return;}
>
> void main(){
>
> volatile static int j;
> CSL_init();
>
> /*fp_bs=fopen("buffersize.txt","r");
> fgets(buffer_sz,10,fp_bs);
> fclose(fp_bs);
> fp_pw=fopen("pulsewidth.txt","r");
> fgets(pulse_width,10,fp_pw);
> fclose(fp_pw);
> freopen("tracevalues.txt","w",stdout);
> printf("%s \n",buffer_sz);
> printf("%s \n",pulse_width);*/
>
> myGPIO_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );
>
> GPIO_config(myGPIO_handle , &MyConfig );
>
> //GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);
>
> GPIO_pinDirection(myGPIO_handle,GPIO_PIN4, GPIO_OUTPUT);
>
> startpll();
>
> EMIF_config(&emifCfg0);
> IRQ_nmiEnable();
> IRQ_globalEnable();
>
> for (j=0; j<=BUFF_SZ; j++)
> {ad_buffer[j]=0;
> }
>
> LOG_printf (&trace, "block cleared");
>
> TimerEventId1 = TIMER_getEventId (hTimer1);
> IRQ_enable (TimerEventId1);
> TIMER_start (hTimer1);
>
> return;
>
> }
>
> void timer_isr ()
>
> { int p=0;
>
> LOG_printf (&trace, "isr");
> analogue_in = *(unsigned volatile int *) INTDSK_CE2;
> ad_buffer[count]=analogue_in & 1023;//2147483648;//1023;
>
> if(count>100 && count <150)
>
> {GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);
> GPIO_pinWrite(myGPIO_handle,GPIO_PIN4,0);
> GPIO_pinDisable (myGPIO_handle,GPIO_PIN4); }
>
> count=count+1;
>
> if (count=00)
>
> //{for (p=0;p<1000;p++)
> //printf("%d \n",ad_buffer[p]);
> printf("Th");
>
> return;
>
> }
>
> Your help will be greatly appreciated
> Regards
> samz
>
> Hi
> >I am new to DSP kit and we are implementing our final year degree project on
it. I am facing some of very basic issues.
> >
> >C6713 is little endain by default. We have to interface emif data pins with
AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data pins on
the emif connector. But the confusion is that which pins should be interfaced
with the ADC pin 0 to pin 11 or pin 20 to pin 31.
> >
> >Secondly the 3 LEDs taht blink when the DSK is turned on, are no more
blinkly, they just stay off. I think because of this our project does not build
properly. Is there any way it can be fixed??
> >
> >Help will be highly appreciated
> >Regards
> >samz
> >
> >_____________________________________
> >
> >
------- End of Original Message -------

_____________________________________
samz,

On Sun, Jul 4, 2010 at 2:04 PM, wrote:

> HI
> First of all thanks alot for replying.
>
> If the adc i am using is 12 bit, wont i be needing 12 bits only?? meaning
> 12 data pins on the emif connector.
>

1. Technically you can connect the pins any way that you want. The software
has to be able to manipulate them.
2. The DSP can process 8, 16, or 32 bits. The most efficient size will
likely be 16 bits. The 12 data bits can be aligned with the MSB at EMIF data
bit 11 or 15 [or anywhere else you want]. It is my preference to force the 4
used bits to a deterministic value [like 0]. You technically do not need to
do this if you always mask off the four bits in software. I just consider it
a good design practice.

>
> At the moment i am connecting data pin 0 to data pin 11. However i am not
> sure if it is correct, i am new to the DSK, and am very confused about which
> pin is the MSB or LSB.
>

Bit 0 is the LSB by default - if you connect your LSB to bit 0 or the 'low
end', you should be okay.

mikedunn

>
> I saw a case study about it too, in that there were also 16 bits going from
> the ADC to the daughtercard however i could not understand how can there be
> 16 lines??
>
> This is the code i am implementing at the moment. I need to generate a
> square pulse using the DSK.
>
> #include "Maycfg.h"
> #include "dsk6713.h"
> #include "target.h"
> #include "stdio.h"
> #include "csl.h"
> #include "csl_cache.h"
>
> #include "csl_timer.h"
> #include "csl_irq.h"
> #include "csl_pll.h"
> #include
> #include
> #include #define INTDSK_CE2 0xA0000000
> #define BUFF_SZ 1000
>
> Uint32 ad_buffer[BUFF_SZ];
>
> static Uint32 TimerEventId1;
> static Uint32 analogue_in = 0;
> static Uint32 count = 0;
>
> //FILE *fp_bs;
> //FILE *fp_pw;
> //FILE *fp_ab;
> //FILE *fopen();
> //char buffer_sz[10] ;
> //char pulse_width[10] ;
> int q=0;
>
> GPIO_Handle myGPIO_handle;
> GPIO_Config MyConfig = { 0x00000000, /* gpgc */
>
> 0x00000000, // gpen --
>
> 0x00000000, // gdir -
>
> 0x00000000, /* gpval */
>
> 0x00000000, /* gphm all interrupts disabled for io pins */
>
> 0x00000000, /* gplm all interrupts to cpu or edma disabled */
>
> 0x00000000 /* gppol -- default state */
>
> };
>
> void timer_isr();
> void startpll(){
>
> // Set main multiplier/divisor
> PLL_RSET(PLLM, 9); // 50MHz x 9 = 450MHz
> PLL_RSET(PLLDIV0, PLL_PLLDIV0_RMK(1, 0)); // 450MHz / 1 = 450MHz
> PLL_RSET(OSCDIV1, PLL_OSCDIV1_RMK(1, 4)); // 50MHz / 5 = 10Mhz
> // Set DSP clock
> PLL_RSET(PLLDIV1, PLL_PLLDIV1_RMK(1,1)); // 450MHz / 2 = 225MHz
> plldelay(20);
> PLL_RSET(PLLDIV2, PLL_PLLDIV2_RMK(1, 3)); // 450MHz / 4 = 112.5MHz
> plldelay(20);
> // Set EMIF clock
> PLL_RSET(PLLDIV3, PLL_PLLDIV3_RMK(1, 4)); // 450MHz / 9 = 50MHz 90MHz
> plldelay(20);
> LOG_printf (&trace, "end of pll");
> return;}
>
> void main(){
>
> volatile static int j;
> CSL_init();
>
> /*fp_bs=fopen("buffersize.txt","r");
> fgets(buffer_sz,10,fp_bs);
> fclose(fp_bs);
> fp_pw=fopen("pulsewidth.txt","r");
> fgets(pulse_width,10,fp_pw);
> fclose(fp_pw);
> freopen("tracevalues.txt","w",stdout);
> printf("%s \n",buffer_sz);
> printf("%s \n",pulse_width);*/
>
> myGPIO_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );
>
> GPIO_config(myGPIO_handle , &MyConfig );
>
> //GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);
>
> GPIO_pinDirection(myGPIO_handle,GPIO_PIN4, GPIO_OUTPUT);
>
> startpll();
>
> EMIF_config(&emifCfg0);
> IRQ_nmiEnable();
> IRQ_globalEnable();
>
> for (j=0; j<=BUFF_SZ; j++)
> {ad_buffer[j]=0;
> }
>
> LOG_printf (&trace, "block cleared");
>
> TimerEventId1 = TIMER_getEventId (hTimer1);
> IRQ_enable (TimerEventId1);
> TIMER_start (hTimer1);
> return;
>
> }
>
> void timer_isr ()
>
> { int p=0;
>
> LOG_printf (&trace, "isr");
> analogue_in = *(unsigned volatile int *) INTDSK_CE2;
> ad_buffer[count]=analogue_in & 1023;//2147483648;//1023;
>
> if(count>100 && count <150)
>
> {GPIO_pinEnable (myGPIO_handle,GPIO_PIN4);
> GPIO_pinWrite(myGPIO_handle,GPIO_PIN4,0);
> GPIO_pinDisable (myGPIO_handle,GPIO_PIN4); }
>
> count=count+1;
>
> if (count=00)
>
> //{for (p=0;p<1000;p++)
> //printf("%d \n",ad_buffer[p]);
> printf("Th");
>
> return;
>
> }
>
> Your help will be greatly appreciated
> Regards
> samz
> Hi
> >I am new to DSP kit and we are implementing our final year degree project
> on it. I am facing some of very basic issues.
> >
> >C6713 is little endain by default. We have to interface emif data pins
> with AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data
> pins on the emif connector. But the confusion is that which pins should be
> interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.
> >
> >Secondly the 3 LEDs taht blink when the DSK is turned on, are no more
> blinkly, they just stay off. I think because of this our project does not
> build properly. Is there any way it can be fixed??
> >
> >Help will be highly appreciated
> >Regards
> >samz
> >
> >_____________________________________
> >
> >
>
>

--
www.dsprelated.com/blogs-1/nf/Mike_Dunn.php
Thanks alot Mike and Richards.

I will definately implement your suggestions soon. I have also implemented our circuit on the microcontroller AVR ATMEGA 32, However both ways i am not getting the accurate result, the problrm with the DSK system is as richards said, with the program.
Can you do me a favour and look at my microcontroller code?? I want to generate a small square pulse and to read back the reflected pulse and the time taken by the pulse to travel. We are implementing simplex coding for OTDR, sending down a matrix of pulses.
Regards
samz

//ICC-AVR application builder : 14/03/2008 10:56:23 Õ
// Target : M32
// Crystal: 11.0592Mhz

#include
#include

#define BinToASCII(t)((t<=9) ? (t|0x30):(t+55))
#define ASCIIToBin(t) ((t>='A'&& t<='F')?t-55:((t>='0' && t<='9') ? t-'0':0))

#define BYTELOW(v) (*((unsigned char *) (&v)))
#define BYTEHIGH(v) (*(((unsigned char *) (&v) + 1)))
//============================#define SPIDDR DDRB
#define SPIPORT PORTB
#define SPIPIN PINB
#define CS 0x10

/*-----------*/
#define LCD_1LINE 0x80
#define LCD_2LINE 0xC0
#define LCD_3LINE 0x94
#define LCD_4LINE 0xD4
#define EN 0x80
#define RS 0x40
#define DB7 0x80

#define FSET_8_BIT 0x03
#define FSET_4_BIT 0x02
#define FSET_4_LINE 0x28
#define FSET_D_OFF 0x08
#define LCD_CLEAR 0x01
#define FSET_ENTRY 0x06
#define FSET_D_ON 0x0E
#define FSET_CUR_OFF 0x0C
#define FSET_HOME 0x0E

//===================================#define LASER 0x20

#define ADC_DATL PINC
#define ADC_DATH PINA

union{
unsigned char BUF[60];
struct
{
unsigned char CH00;
unsigned char CH01;
unsigned char CH02;
unsigned char CH03;
unsigned char CH04;
unsigned char CH05;
unsigned char CH06;
unsigned char CH07;
unsigned char CH08;
unsigned char CH09;
unsigned char CH10;
unsigned char CH11;
unsigned char CH12;
unsigned char CH13;
unsigned char CH14;
unsigned char CH15;
unsigned char CH16;
unsigned char CH17;
unsigned char CH18;
unsigned char CH19;
unsigned char CH20;
unsigned char CH21;
unsigned char CH22;
unsigned char CH23;
unsigned char CH24;
unsigned char CH25;
unsigned char CH26;
unsigned char CH27;
unsigned char CH28;
unsigned char CH29;
unsigned char CH30;
unsigned char CH31;
unsigned char CH32;
unsigned char CH33;
unsigned char CH34;
unsigned char CH35;
unsigned char CH36;
unsigned char CH37;
unsigned char CH38;
unsigned char CH39;
unsigned char CH40;
unsigned char CH41;
unsigned char CH42;
unsigned char CH43;
unsigned char CH44;
unsigned char CH45;
unsigned char CH46;
unsigned char CH47;
unsigned char CH48;
unsigned char CH49;
unsigned char CH50;
unsigned char CH51;
unsigned char CH52;
unsigned char CH53;
unsigned char CH54;
unsigned char CH55;
unsigned char CH56;
unsigned char CH57;
unsigned char CH58;
unsigned char CH59;
}BYT;
}ATD_BUF1;

// buffer FOR ROW 2 reading

union{
unsigned char BUF[60];
struct{
unsigned char CH00;
unsigned char CH01;
unsigned char CH02;
unsigned char CH03;
unsigned char CH04;
unsigned char CH05;
unsigned char CH06;
unsigned char CH07;
unsigned char CH08;
unsigned char CH09;
unsigned char CH10;
unsigned char CH11;
unsigned char CH12;
unsigned char CH13;
unsigned char CH14;
unsigned char CH15;
unsigned char CH16;
unsigned char CH17;
unsigned char CH18;
unsigned char CH19;
unsigned char CH20;
unsigned char CH21;
unsigned char CH22;
unsigned char CH23;
unsigned char CH24;
unsigned char CH25;
unsigned char CH26;
unsigned char CH27;
unsigned char CH28;
unsigned char CH29;
unsigned char CH30;
unsigned char CH31;
unsigned char CH32;
unsigned char CH33;
unsigned char CH34;
unsigned char CH35;
unsigned char CH36;
unsigned char CH37;
unsigned char CH38;
unsigned char CH39;
unsigned char CH40;
unsigned char CH41;
unsigned char CH42;
unsigned char CH43;
unsigned char CH44;
unsigned char CH45;
unsigned char CH46;
unsigned char CH47;
unsigned char CH48;
unsigned char CH49;
unsigned char CH50;
unsigned char CH51;
unsigned char CH52;
unsigned char CH53;
unsigned char CH54;
unsigned char CH55;
unsigned char CH56;
unsigned char CH57;
unsigned char CH58;
unsigned char CH59;
}BYT;
}ATD_BUF2;

// BUFFER for ROW 3 READING
union{
unsigned char BUF[60];
struct{
unsigned char CH00;
unsigned char CH01;
unsigned char CH02;
unsigned char CH03;
unsigned char CH04;
unsigned char CH05;
unsigned char CH06;
unsigned char CH07;
unsigned char CH08;
unsigned char CH09;
unsigned char CH10;
unsigned char CH11;
unsigned char CH12;
unsigned char CH13;
unsigned char CH14;
unsigned char CH15;
unsigned char CH16;
unsigned char CH17;
unsigned char CH18;
unsigned char CH19;
unsigned char CH20;
unsigned char CH21;
unsigned char CH22;
unsigned char CH23;
unsigned char CH24;
unsigned char CH25;
unsigned char CH26;
unsigned char CH27;
unsigned char CH28;
unsigned char CH29;
unsigned char CH30;
unsigned char CH31;
unsigned char CH32;
unsigned char CH33;
unsigned char CH34;
unsigned char CH35;
unsigned char CH36;
unsigned char CH37;
unsigned char CH38;
unsigned char CH39;
unsigned char CH40;
unsigned char CH41;
unsigned char CH42;
unsigned char CH43;
unsigned char CH44;
unsigned char CH45;
unsigned char CH46;
unsigned char CH47;
unsigned char CH48;
unsigned char CH49;
unsigned char CH50;
unsigned char CH51;
unsigned char CH52;
unsigned char CH53;
unsigned char CH54;
unsigned char CH55;
unsigned char CH56;
unsigned char CH57;
unsigned char CH58;
unsigned char CH59;
}BYT;
}ATD_BUF3;

unsigned int HMAT_R1 [30];
unsigned int HMAT_R2 [30];
unsigned int HMAT_R3 [30];

void FAULT_LOC_CALC(unsigned int OFST1,
unsigned int OFST2,
unsigned int OFST3,
unsigned int THREH_HOLD,
unsigned char BUF_END
);
void HM_AVG_SEND(unsigned int HM_AVG[]);

// Target : M32 Crystal: 11.0592Mhz

void port_init(void)
{

DDRABCD=0xFF;
PORTA=PORTB=PORTC=PORTD=0xFF;
}

//UART0 initialize
// desired baud rate: 19200
// actual: baud rate:19200 (0.0%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x23; //set baud rate lo //
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
port_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00;
}

/*
unsigned char ReceiveByte(void)
{
while(!(UCSRA & BIT(RXC))) ;
return UDR;
}*/

void SEND_CHAR_UART(char ch)
{
while(!(UCSRA & BIT(UDRE))) ;
UDR = ch;
}

void SendStr(const char *ch)
{ while(*ch != 0x00) SEND_CHAR_UART(*ch++);}
/**/
void PRINT_ASCII (unsigned char PRNT)
{
unsigned char PRN=0;

PRN=PRNT>>4;
SEND_CHAR_UART(BinToASCII(PRN));

PRN=PRNT&0x0F;
SEND_CHAR_UART(BinToASCII(PRN));

}
//================================void SpiInit()
{
DDRB |= 0xB0; // Set SCK, MOSI & SS as outputs
PORTB &= 0x5F; // clear bits MOSI, & SCK
SPCR = 0x53;
}
//================================unsigned char CHAR_SPI1(unsigned char byte)

{
SPIPORT |= CS;

SPDR = byte;
while (!(SPSR & 0x80));
byte = SPDR;

SPIPORT &= ~CS;
return byte;
}

//==============================================// LCD LIB FUNCTION
//==============================================//**************************************
// void Delay_1ms(void)
//**************************************
void Delay_1ms(unsigned long Del)
{
int i;
while (Del--)
{ for (i=0;i<2000;i++); }
}
/*-----------------------*/
void LCD_CMD ( unsigned char CMD)
{
unsigned char MSN, LSN;
//unsigned int i;

MSN=( CMD>>4);
LSN=( CMD&0x0f);

CHAR_SPI1(MSN); CHAR_SPI1(MSN|EN); CHAR_SPI1(MSN);
Delay_1ms(2);
CHAR_SPI1(LSN); CHAR_SPI1(LSN|EN); CHAR_SPI1(LSN);
Delay_1ms(2);

return ;

}
/*-----------------*/
void LCD_CHAR ( unsigned char CMD)
{
unsigned char MSN, LSN;

MSN=( CMD>>4)|RS;
LSN=( CMD&0x0f)|RS;

CHAR_SPI1(MSN); CHAR_SPI1(MSN|EN); CHAR_SPI1(MSN);
Delay_1ms(1);

CHAR_SPI1(LSN); CHAR_SPI1(LSN|EN); CHAR_SPI1(LSN);;
Delay_1ms(1);
}
/*----------*/
void LCD_INIT ( void)
{

// Delay_1ms(1000); //15MSEC is recommed after Reset

LCD_CMD(FSET_8_BIT ); Delay_1ms(1);
LCD_CMD(FSET_8_BIT ); Delay_1ms(1);
LCD_CMD(FSET_8_BIT ); Delay_1ms(1);

LCD_CMD(FSET_4_BIT ); Delay_1ms(1);
LCD_CMD(FSET_4_LINE ); // Delay_1ms(1);

LCD_CMD( FSET_D_OFF ); // Delay_1ms(1);
LCD_CMD(LCD_CLEAR); // Delay_1ms(1);
LCD_CMD(FSET_ENTRY ); // Delay_1ms(1);
LCD_CMD(FSET_D_ON ); // Delay_1ms(1);

LCD_CMD( FSET_HOME); // Delay_1ms(1);
LCD_CMD( FSET_CUR_OFF);
// Delay_1ms(1);
}

//===============================================void LCD_Print(char MSG[])
{
char MSG_INDEX=0;
while(MSG[MSG_INDEX]!='\0')
{
LCD_CHAR(MSG[MSG_INDEX]);
MSG_INDEX++;
}
}
//===============================================void LCD_PRN_POS(unsigned char MSG[],unsigned char POS )
{
char MSG_INDEX=0;
LCD_CMD( POS);
while(MSG[MSG_INDEX]!='\0')
{
LCD_CHAR(MSG[MSG_INDEX]);
MSG_INDEX++;
}
}

//===============================================void LCD_Position(unsigned char pos)
{
LCD_CMD(pos);

}
/***************LCD_PrintUI***********************/
void LCD_PrintUI(unsigned char pos,unsigned int i)
{
pos+=5;
while(i>0)
{
LCD_Position(pos);
LCD_CHAR((i%10)+0x30);
pos--;
i/;
}
}

//===============================================================
void READ_ADC_ROW1 (void)
{

ATD_BUF1.BYT.CH00 C_DATH; ATD_BUF1.BYT.CH01 C_DATL;
ATD_BUF1.BYT.CH02 C_DATH; ATD_BUF1.BYT.CH03 C_DATL;
ATD_BUF1.BYT.CH04 C_DATH; ATD_BUF1.BYT.CH05 C_DATL;
ATD_BUF1.BYT.CH06 C_DATH; ATD_BUF1.BYT.CH07 C_DATL;
ATD_BUF1.BYT.CH08 C_DATH; ATD_BUF1.BYT.CH09 C_DATL;

//10 rdS
ATD_BUF1.BYT.CH10 C_DATH; ATD_BUF1.BYT.CH11 C_DATL;
ATD_BUF1.BYT.CH12 C_DATH; ATD_BUF1.BYT.CH13 C_DATL;
ATD_BUF1.BYT.CH14 C_DATH; ATD_BUF1.BYT.CH15 C_DATL;
ATD_BUF1.BYT.CH16 C_DATH; ATD_BUF1.BYT.CH17 C_DATL;
ATD_BUF1.BYT.CH18 C_DATH; ATD_BUF1.BYT.CH19 C_DATL;
// 20 RDS
ATD_BUF1.BYT.CH20 C_DATH; ATD_BUF1.BYT.CH21 C_DATL;
ATD_BUF1.BYT.CH22 C_DATH; ATD_BUF1.BYT.CH23 C_DATL;
ATD_BUF1.BYT.CH24 C_DATH; ATD_BUF1.BYT.CH25 C_DATL;
ATD_BUF1.BYT.CH26 C_DATH; ATD_BUF1.BYT.CH27 C_DATL;
ATD_BUF1.BYT.CH28 C_DATH; ATD_BUF1.BYT.CH29 C_DATL;
// 30 RDS
ATD_BUF1.BYT.CH30 C_DATH; ATD_BUF1.BYT.CH31 C_DATL;
ATD_BUF1.BYT.CH32 C_DATH; ATD_BUF1.BYT.CH33 C_DATL;
ATD_BUF1.BYT.CH34 C_DATH; ATD_BUF1.BYT.CH35 C_DATL;
ATD_BUF1.BYT.CH36 C_DATH; ATD_BUF1.BYT.CH37 C_DATL;
ATD_BUF1.BYT.CH38 C_DATH; ATD_BUF1.BYT.CH39 C_DATL;
//40 rds

ATD_BUF1.BYT.CH40 C_DATH; ATD_BUF1.BYT.CH41 C_DATL;
ATD_BUF1.BYT.CH42 C_DATH; ATD_BUF1.BYT.CH43 C_DATL;
ATD_BUF1.BYT.CH44 C_DATH; ATD_BUF1.BYT.CH45 C_DATL;
ATD_BUF1.BYT.CH46 C_DATH; ATD_BUF1.BYT.CH47 C_DATL;
ATD_BUF1.BYT.CH48 C_DATH; ATD_BUF1.BYT.CH49 C_DATL;
//50 rds
/* ATD_BUF1.BYT.CH50 C_DATH; ATD_BUF1.BYT.CH51 C_DATL;
ATD_BUF1.BYT.CH52 C_DATH; ATD_BUF1.BYT.CH53 C_DATL;
ATD_BUF1.BYT.CH54 C_DATH; ATD_BUF1.BYT.CH55 C_DATL;
ATD_BUF1.BYT.CH56 C_DATH; ATD_BUF1.BYT.CH57 C_DATL;
ATD_BUF1.BYT.CH58 C_DATH; ATD_BUF1.BYT.CH59 C_DATL;
*/

}

//===============================================void READ_ADC_ROW2 (void)
{

ATD_BUF2.BYT.CH00 C_DATH; ATD_BUF2.BYT.CH01 C_DATL;
ATD_BUF2.BYT.CH02 C_DATH; ATD_BUF2.BYT.CH03 C_DATL;
ATD_BUF2.BYT.CH04 C_DATH; ATD_BUF2.BYT.CH05 C_DATL;
ATD_BUF2.BYT.CH06 C_DATH; ATD_BUF2.BYT.CH07 C_DATL;
ATD_BUF2.BYT.CH08 C_DATH; ATD_BUF2.BYT.CH09 C_DATL;

//10 rdS
ATD_BUF2.BYT.CH10 C_DATH; ATD_BUF2.BYT.CH11 C_DATL;
ATD_BUF2.BYT.CH12 C_DATH; ATD_BUF2.BYT.CH13 C_DATL;
ATD_BUF2.BYT.CH14 C_DATH; ATD_BUF2.BYT.CH15 C_DATL;
ATD_BUF2.BYT.CH16 C_DATH; ATD_BUF2.BYT.CH17 C_DATL;
ATD_BUF2.BYT.CH18 C_DATH; ATD_BUF2.BYT.CH19 C_DATL;
// 20 RDS
ATD_BUF2.BYT.CH20 C_DATH; ATD_BUF2.BYT.CH21 C_DATL;
ATD_BUF2.BYT.CH22 C_DATH; ATD_BUF2.BYT.CH23 C_DATL;
ATD_BUF2.BYT.CH24 C_DATH; ATD_BUF2.BYT.CH25 C_DATL;
ATD_BUF2.BYT.CH26 C_DATH; ATD_BUF2.BYT.CH27 C_DATL;
ATD_BUF2.BYT.CH28 C_DATH; ATD_BUF2.BYT.CH29 C_DATL;
// 30 RDS
ATD_BUF2.BYT.CH30 C_DATH; ATD_BUF2.BYT.CH31 C_DATL;
ATD_BUF2.BYT.CH32 C_DATH; ATD_BUF2.BYT.CH33 C_DATL;
ATD_BUF2.BYT.CH34 C_DATH; ATD_BUF2.BYT.CH35 C_DATL;
ATD_BUF2.BYT.CH36 C_DATH; ATD_BUF2.BYT.CH37 C_DATL;
ATD_BUF2.BYT.CH38 C_DATH; ATD_BUF2.BYT.CH39 C_DATL;
//40 rds

ATD_BUF2.BYT.CH40 C_DATH; ATD_BUF2.BYT.CH41 C_DATL;
ATD_BUF2.BYT.CH42 C_DATH; ATD_BUF2.BYT.CH43 C_DATL;
ATD_BUF2.BYT.CH44 C_DATH; ATD_BUF2.BYT.CH45 C_DATL;
ATD_BUF2.BYT.CH46 C_DATH; ATD_BUF2.BYT.CH47 C_DATL;
ATD_BUF2.BYT.CH48 C_DATH; ATD_BUF2.BYT.CH49 C_DATL;
//50 rds
/* ATD_BUF2.BYT.CH50 C_DATH; ATD_BUF2.BYT.CH51 C_DATL;
ATD_BUF2.BYT.CH52 C_DATH; ATD_BUF2.BYT.CH53 C_DATL;
ATD_BUF2.BYT.CH54 C_DATH; ATD_BUF2.BYT.CH55 C_DATL;
ATD_BUF2.BYT.CH56 C_DATH; ATD_BUF2.BYT.CH57 C_DATL;
ATD_BUF2.BYT.CH58 C_DATH; ATD_BUF2.BYT.CH59 C_DATL;
*/

}
//=================================================
void READ_ADC_ROW3 (void)
{

ATD_BUF3.BYT.CH00 C_DATH; ATD_BUF3.BYT.CH01 C_DATL;
ATD_BUF3.BYT.CH02 C_DATH; ATD_BUF3.BYT.CH03 C_DATL;
ATD_BUF3.BYT.CH04 C_DATH; ATD_BUF3.BYT.CH05 C_DATL;
ATD_BUF3.BYT.CH06 C_DATH; ATD_BUF3.BYT.CH07 C_DATL;
ATD_BUF3.BYT.CH08 C_DATH; ATD_BUF3.BYT.CH09 C_DATL;

//10 rdS
ATD_BUF3.BYT.CH10 C_DATH; ATD_BUF3.BYT.CH11 C_DATL;
ATD_BUF3.BYT.CH12 C_DATH; ATD_BUF3.BYT.CH13 C_DATL;
ATD_BUF3.BYT.CH14 C_DATH; ATD_BUF3.BYT.CH15 C_DATL;
ATD_BUF3.BYT.CH16 C_DATH; ATD_BUF3.BYT.CH17 C_DATL;
ATD_BUF3.BYT.CH18 C_DATH; ATD_BUF3.BYT.CH19 C_DATL;
// 20 RDS
ATD_BUF3.BYT.CH20 C_DATH; ATD_BUF3.BYT.CH21 C_DATL;
ATD_BUF3.BYT.CH22 C_DATH; ATD_BUF3.BYT.CH23 C_DATL;
ATD_BUF3.BYT.CH24 C_DATH; ATD_BUF3.BYT.CH25 C_DATL;
ATD_BUF3.BYT.CH26 C_DATH; ATD_BUF3.BYT.CH27 C_DATL;
ATD_BUF3.BYT.CH28 C_DATH; ATD_BUF3.BYT.CH29 C_DATL;
// 30 RDS
ATD_BUF3.BYT.CH30 C_DATH; ATD_BUF3.BYT.CH31 C_DATL;
ATD_BUF3.BYT.CH32 C_DATH; ATD_BUF3.BYT.CH33 C_DATL;
ATD_BUF3.BYT.CH34 C_DATH; ATD_BUF3.BYT.CH35 C_DATL;
ATD_BUF3.BYT.CH36 C_DATH; ATD_BUF3.BYT.CH37 C_DATL;
ATD_BUF3.BYT.CH38 C_DATH; ATD_BUF3.BYT.CH39 C_DATL;
//40 rds

ATD_BUF3.BYT.CH40 C_DATH; ATD_BUF3.BYT.CH41 C_DATL;
ATD_BUF3.BYT.CH42 C_DATH; ATD_BUF3.BYT.CH43 C_DATL;
ATD_BUF3.BYT.CH44 C_DATH; ATD_BUF3.BYT.CH45 C_DATL;
ATD_BUF3.BYT.CH46 C_DATH; ATD_BUF3.BYT.CH47 C_DATL;
ATD_BUF3.BYT.CH48 C_DATH; ATD_BUF3.BYT.CH49 C_DATL;
//50 rds
/* ATD_BUF3.BYT.CH50 C_DATH; ATD_BUF3.BYT.CH51 C_DATL;
ATD_BUF3.BYT.CH52 C_DATH; ATD_BUF3.BYT.CH53 C_DATL;
ATD_BUF3.BYT.CH54 C_DATH; ATD_BUF3.BYT.CH55 C_DATL;
ATD_BUF3.BYT.CH56 C_DATH; ATD_BUF3.BYT.CH57 C_DATL;
ATD_BUF3.BYT.CH58 C_DATH; ATD_BUF3.BYT.CH59 C_DATL;
*/

}
//=================================void SEND_ADC_BUFFER( unsigned char BUF[])
{

unsigned char BUF_PTR;

SEND_CHAR_UART('@');
for (BUF_PTR=0;BUF_PTR<50;BUF_PTR=BUF_PTR+2)
{
SEND_CHAR_UART(BUF[BUF_PTR]&0X0F);
SEND_CHAR_UART(BUF[BUF_PTR+1]);

}

}

//=================================void SEND_HMAT( unsigned int BUF[])
{

unsigned char BUF_PTR;

SEND_CHAR_UART('@');

for (BUF_PTR=0;BUF_PTR<25; BUF_PTR++)
{
SEND_CHAR_UART(BYTEHIGH(BUF[BUF_PTR]));
SEND_CHAR_UART(BYTELOW(BUF[BUF_PTR]));

}

}

volatile unsigned char PW_OPT=0;
volatile unsigned char STATUS=0;
volatile unsigned char SCR=0;

//====================================================// KEY PROCESS
unsigned char KEY_PROCESS(unsigned char PW)
{

unsigned char INPUT=0;
unsigned char KEY=0;
unsigned char TEMP=0;

TEMP=PW;

INPUT=PINB; Delay_1ms(50); INPUT=PINB;

INPUT=0x0F&INPUT;

if(INPUT!=0x0F)
{
if(INPUT==0x0E) // START
{
LCD_CMD(LCD_CLEAR);
LCD_PRN_POS("Trigger IS SEND ",LCD_1LINE);
STATUS=1;
}

if(INPUT==0x0D) // F1
{
if(TEMP<3)
TEMP++;
}

if(INPUT==0x0B) // F2
{
if(TEMP>0)
TEMP--;
}

if(INPUT==0x07) // F3
{
if(SCR==1)
SCR=0;
// SEND_CHAR_UART

}
INPUT = 0;
//========================= if(TEMP==0)
{
LCD_PRN_POS(" PW = 180nsec ",LCD_4LINE);
}
else
if(TEMP==1)
{
LCD_PRN_POS(" PW = 360nsec ",LCD_4LINE);
}
else
if(TEMP==2)
{
LCD_PRN_POS(" PW = 540nsec ",LCD_4LINE);
}
else
if(TEMP==3)
{
LCD_PRN_POS(" PW = 1.08usec ",LCD_4LINE);
}

}
return TEMP;
}
//=============================================================#define ROW10() PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//1010
#define ROW20() PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//011
#define ROW30() PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//110

//===============================================// Function to SEND and receive
// PW_OPT=0 , PW0
// OFSET1 0*4r0
// OFSET2 0*3T0
// OFSET3 0*3T0

void TRIG_RECV_PW0(void)
{

ROW10(); READ_ADC_ROW1 ();
ROW10(); READ_ADC_ROW2 ();
ROW10(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R1);

ROW20(); READ_ADC_ROW1 ();
ROW20(); READ_ADC_ROW2 ();
ROW20(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R2);

ROW30(); READ_ADC_ROW1 ();
ROW30(); READ_ADC_ROW2 ();
ROW30(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R3);

}
//=====================================================#define ROW11() PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//1010
#define ROW21() PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//011
#define ROW31() PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//110

//===============================================// Function to SEND and receive
// PW_OPT=1 , PW60
// OFSET1 0*760
// OFSET2 0*50
// OFSET3 0*50

void TRIG_RECV_PW1(void)
{
ROW11(); READ_ADC_ROW1 ();
ROW11(); READ_ADC_ROW2 ();
ROW11(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R1);

ROW21(); READ_ADC_ROW1 ();
ROW21(); READ_ADC_ROW2 ();
ROW21(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R2);

ROW31(); READ_ADC_ROW1 ();
ROW31(); READ_ADC_ROW2 ();
ROW31(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R3);

}
//===============================================// Functions to SEND and receive
// PW_OPT=2 , PWT0
// OFSET1 0*1000
// OFSET2 0*700
// OFSET3 0**700
void ROW12(void)//101
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}

void ROW22(void) //011
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}

void ROW32(void) //110
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}
//==void TRIG_RECV_PW2(void)
{
ROW12(); READ_ADC_ROW1 ();
ROW12(); READ_ADC_ROW2 ();
ROW12(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R1);

ROW22(); READ_ADC_ROW1 ();
ROW22(); READ_ADC_ROW2 ();
ROW22(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R2);

ROW32(); READ_ADC_ROW1 ();
ROW32(); READ_ADC_ROW2 ();
ROW32(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R3);

}

//===============================================// Functions to SEND and receive
// PW_OPT=2 , PW80
// OFSET1 0*19400 nsec
// OFSET2 0*13#40
// OFSET3 0*13#40
void ROW13(void)//101
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}

void ROW23(void)//011
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}

void ROW33(void)//110
{
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
PORTA=PORTA&(~LASER);
}

void TRIG_RECV_PW3(void)
{
ROW13(); READ_ADC_ROW1 ();
ROW13(); READ_ADC_ROW2 ();
ROW13(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R1);

ROW23(); READ_ADC_ROW1 ();
ROW23(); READ_ADC_ROW2 ();
ROW23(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R2);

ROW33(); READ_ADC_ROW1 ();
ROW33(); READ_ADC_ROW2 ();
ROW33(); READ_ADC_ROW3 ();
HM_AVG_SEND(HMAT_R3);

}

//========================================// void HM_AVG_SEND(unsigned int HM_AVG[])
//=======================================void HM_AVG_SEND(unsigned int HM_AVG[])
{
unsigned char TMP0=0;
unsigned char TMP1=0;

for(TMP0=0;TMP0<50;TMP0=TMP0+2)
{
BYTEHIGH(HM_AVG[TMP1])= ((ATD_BUF1.BUF[TMP0]&0x0F)+
(ATD_BUF2.BUF[TMP0]&0x0F)+
(ATD_BUF3.BUF[TMP0]&0x0F))/3;

BYTELOW(HM_AVG[TMP1])=((ATD_BUF1.BUF[TMP0+1])+
(ATD_BUF2.BUF[TMP0+1])+
(ATD_BUF3.BUF[TMP0+1]))/3;
TMP1++;
}

SEND_ADC_BUFFER(ATD_BUF1.BUF);
SEND_ADC_BUFFER(ATD_BUF2.BUF);
SEND_ADC_BUFFER(ATD_BUF3.BUF);
SEND_HMAT(HM_AVG);
}
//=============================================// void FAULT_LOC_CALC
//=========================================void FAULT_LOC_CALC(unsigned int OFST1,
unsigned int OFST2,
unsigned int OFST3,
unsigned int THREH_HOLD,
unsigned char BUF_END
)
{

unsigned char RPTR=0;
// READ TIME betwenn two consective readings
unsigned int RD_TIME = 360;
// SPEED OF LIGHT IN 1USEC on Fiber-optic
unsigned char FIB_VEL= 200;

float RESULT =0;
unsigned int S1 =0;
unsigned int S2 =0;
unsigned int S3 =0;
unsigned int S_AVG =0;

for(RPTR=0;RPTR {
if(HMAT_R1[RPTR]>THREH_HOLD)
{
RESULT= OFST1+(RPTR*RD_TIME);
RESULT=(RESULT/1000); //t
S1=RESULT*FIB_VEL; //S
break;
}
}

//SEND_CHAR_UART(BYTEHIGH(S1));SEND_CHAR_UART(BYTELOW(S1));

for(RPTR=0;RPTR {
if(HMAT_R2[RPTR]>THREH_HOLD)
{
RESULT= OFST2+(RPTR*RD_TIME);;
RESULT=(RESULT/1000); //t
S2=RESULT*200; //S
break;
}
}

//SEND_CHAR_UART(BYTEHIGH(S2));SEND_CHAR_UART(BYTELOW(S2));

for(RPTR=0;RPTR {
if(HMAT_R3[RPTR]>THREH_HOLD)
{
RESULT= OFST3+(RPTR*RD_TIME);
RESULT=(RESULT/1000); //t
S3=RESULT*200; //S
break;
}
}
//SEND_CHAR_UART(BYTEHIGH(S3));SEND_CHAR_UART(BYTELOW(S3));

S_AVG=((S1+S2+S3)/3)/2;

/*SEND_CHAR_UART(BYTEHIGH(S_AVG));
SEND_CHAR_UART(BYTELOW(S_AVG)); */

LCD_CMD(LCD_CLEAR);
LCD_PRN_POS("FAULT PLACE AT ",LCD_1LINE);
LCD_PrintUI(LCD_2LINE+3,S_AVG);
LCD_PRN_POS("METER ",LCD_2LINE+10);
LCD_PRN_POS("F3 : NEW OBSERVATION ",LCD_4LINE);

}

/*---*/
/* ************************************************************************ *\
Function: 'main()'.
\* ************************************************************************ */

void main(void)
{

init_devices(); // set the baudrate to 19,200 bps using a 14.7456MHz crystal.
Delay_1ms(100);
//LASER & DATA BUS DIRECTION SET
PORTC=0x0;
PORTA=0xF0;
DDRC=0x0; // ALL PORTC IS INPUT for ADC_0-7
DDRAA&0xF0;// Upper Nibble of PORT id INPUT for ADC_8-11
DDRAA|0x20;// PORTA_BIT5 =LASER as OUTPUT
PORTA=PORTA&(~LASER);

//============================SpiInit();
SPCR = 0x50;SPSR |=0x01;
LCD_INIT();
//============================
// STARTING LCD SCREEN
LCD_CMD(LCD_CLEAR);
LCD_PRN_POS("OPTICAL LOOP TESTER",LCD_1LINE);
LCD_PRN_POS(" Syndicate #: 25",LCD_2LINE);
LCD_PRN_POS("TE-43C :Samia, Maria ",LCD_3LINE);
LCD_PRN_POS(" Saad, Asad ",LCD_4LINE);
Delay_1ms(1000);
LCD_CMD(LCD_CLEAR); LCD_CMD(LCD_CLEAR);
/*-------------*/

while (1) // Now do this forever.
{
PW_OPT=KEY_PROCESS(PW_OPT);
if(SCR==0)
{
LCD_CMD(LCD_CLEAR);
LCD_PRN_POS("START: SEND PULSES ",LCD_1LINE);
LCD_PRN_POS("F1: Pulse Width + ",LCD_2LINE);
LCD_PRN_POS("F2: Pulse Width -",LCD_3LINE);
LCD_PRN_POS(" PW = 180nsec ",LCD_4LINE);
SCR=1;
}
//START STATUS
if(STATUS==1)
{

if(PW_OPT==0)
{
TRIG_RECV_PW0();
//Testing FAKE VALUES
// HMAT_R1[11]%50; HMAT_R2[12](00; HMAT_R3[13]!50;
FAULT_LOC_CALC(720,540,540,2048,25);

}
// OPTION 1 PW 60;
if(PW_OPT==1)
{
TRIG_RECV_PW1();
//Testing FAKE VALUES
//HMAT_R1[6]%50; HMAT_R2[8](00; HMAT_R3[7]!50;
FAULT_LOC_CALC(1260,900,900,2048,25);
}

// OPTION 1 PW T0;
if(PW_OPT==2)
{
TRIG_RECV_PW2();

//Testing FAKE VALUES
//HMAT_R1[11]%50; HMAT_R2[14](00; HMAT_R3[13]!50;
FAULT_LOC_CALC(1800,1200,1200,2048,25);
}

// OPTION 1 PW 80;
if(PW_OPT==3)
{
TRIG_RECV_PW3();
//Testing FAKE VALUES
HMAT_R1[11]%50; HMAT_R2[14](00; HMAT_R3[13]!50;
FAULT_LOC_CALC(3400,2300,2300,2048,25);
}

PW_OPT=0;
STATUS=0;
}
//END STATUS
}
//while 1
} // main

Hi
>I am new to DSP kit and we are implementing our final year degree project on it. I am facing some of very basic issues.
>
>C6713 is little endain by default. We have to interface emif data pins with AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data pins on the emif connector. But the confusion is that which pins should be interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.
>
>Secondly the 3 LEDs taht blink when the DSK is turned on, are no more blinkly, they just stay off. I think because of this our project does not build properly. Is there any way it can be fixed??
>
>Help will be highly appreciated
>Regards
>samz
>
>_____________________________________

_____________________________________
Samz,

On Mon, Jul 5, 2010 at 11:38 AM, wrote:

> Thanks alot Mike and Richards.
>
> I will definately implement your suggestions soon. I have also implemented
> our circuit on the microcontroller AVR ATMEGA 32, However both ways i am not
> getting the accurate result, the problrm with the DSK system is as richards
> said, with the program.
> Can you do me a favour and look at my microcontroller code?? I want to
> generate a small square pulse and to read back the reflected pulse and the
> time taken by the pulse to travel. We are implementing simplex coding for
> OTDR, sending down a matrix of pulses.
>

My advice is to follow a KIS [Keep It Simple] building block approach.
1. Get your pieces [generate square wave, etc] working and debugged.
2. Begin integrating them one at a time - debug as you go.
It is much easier to debug when you have a single focus [at least it is for
me].

I do not have the time or inclination to look at your code.

mikedunn

> Regards
> samz
>
> //ICC-AVR application builder : 14/03/2008 10:56:23 br /> > // Target : M32
> // Crystal: 11.0592Mhz
>
> #include
> #include #define BinToASCII(t)((t<=9) ? (t|0x30):(t+55))
> #define ASCIIToBin(t) ((t>='A'&& t<='F')?t-55:((t>='0' && t<='9') ?
> t-'0':0))
>
> #define BYTELOW(v) (*((unsigned char *) (&v)))
> #define BYTEHIGH(v) (*(((unsigned char *) (&v) + 1)))
> //============================> #define SPIDDR DDRB
> #define SPIPORT PORTB
> #define SPIPIN PINB
> #define CS 0x10
>
> /*-----------*/
> #define LCD_1LINE 0x80
> #define LCD_2LINE 0xC0
> #define LCD_3LINE 0x94
> #define LCD_4LINE 0xD4
> #define EN 0x80
> #define RS 0x40
> #define DB7 0x80
>
> #define FSET_8_BIT 0x03
> #define FSET_4_BIT 0x02
> #define FSET_4_LINE 0x28
> #define FSET_D_OFF 0x08
> #define LCD_CLEAR 0x01
> #define FSET_ENTRY 0x06
> #define FSET_D_ON 0x0E
> #define FSET_CUR_OFF 0x0C
> #define FSET_HOME 0x0E
>
> //===================================> #define LASER 0x20
>
> #define ADC_DATL PINC
> #define ADC_DATH PINA
> union{
> unsigned char BUF[60];
> struct
> {
> unsigned char CH00;
> unsigned char CH01;
> unsigned char CH02;
> unsigned char CH03;
> unsigned char CH04;
> unsigned char CH05;
> unsigned char CH06;
> unsigned char CH07;
> unsigned char CH08;
> unsigned char CH09;
> unsigned char CH10;
> unsigned char CH11;
> unsigned char CH12;
> unsigned char CH13;
> unsigned char CH14;
> unsigned char CH15;
> unsigned char CH16;
> unsigned char CH17;
> unsigned char CH18;
> unsigned char CH19;
> unsigned char CH20;
> unsigned char CH21;
> unsigned char CH22;
> unsigned char CH23;
> unsigned char CH24;
> unsigned char CH25;
> unsigned char CH26;
> unsigned char CH27;
> unsigned char CH28;
> unsigned char CH29;
> unsigned char CH30;
> unsigned char CH31;
> unsigned char CH32;
> unsigned char CH33;
> unsigned char CH34;
> unsigned char CH35;
> unsigned char CH36;
> unsigned char CH37;
> unsigned char CH38;
> unsigned char CH39;
> unsigned char CH40;
> unsigned char CH41;
> unsigned char CH42;
> unsigned char CH43;
> unsigned char CH44;
> unsigned char CH45;
> unsigned char CH46;
> unsigned char CH47;
> unsigned char CH48;
> unsigned char CH49;
> unsigned char CH50;
> unsigned char CH51;
> unsigned char CH52;
> unsigned char CH53;
> unsigned char CH54;
> unsigned char CH55;
> unsigned char CH56;
> unsigned char CH57;
> unsigned char CH58;
> unsigned char CH59;
> }BYT;
> }ATD_BUF1;
> // buffer FOR ROW 2 reading
>
> union{
> unsigned char BUF[60];
> struct{
> unsigned char CH00;
> unsigned char CH01;
> unsigned char CH02;
> unsigned char CH03;
> unsigned char CH04;
> unsigned char CH05;
> unsigned char CH06;
> unsigned char CH07;
> unsigned char CH08;
> unsigned char CH09;
> unsigned char CH10;
> unsigned char CH11;
> unsigned char CH12;
> unsigned char CH13;
> unsigned char CH14;
> unsigned char CH15;
> unsigned char CH16;
> unsigned char CH17;
> unsigned char CH18;
> unsigned char CH19;
> unsigned char CH20;
> unsigned char CH21;
> unsigned char CH22;
> unsigned char CH23;
> unsigned char CH24;
> unsigned char CH25;
> unsigned char CH26;
> unsigned char CH27;
> unsigned char CH28;
> unsigned char CH29;
> unsigned char CH30;
> unsigned char CH31;
> unsigned char CH32;
> unsigned char CH33;
> unsigned char CH34;
> unsigned char CH35;
> unsigned char CH36;
> unsigned char CH37;
> unsigned char CH38;
> unsigned char CH39;
> unsigned char CH40;
> unsigned char CH41;
> unsigned char CH42;
> unsigned char CH43;
> unsigned char CH44;
> unsigned char CH45;
> unsigned char CH46;
> unsigned char CH47;
> unsigned char CH48;
> unsigned char CH49;
> unsigned char CH50;
> unsigned char CH51;
> unsigned char CH52;
> unsigned char CH53;
> unsigned char CH54;
> unsigned char CH55;
> unsigned char CH56;
> unsigned char CH57;
> unsigned char CH58;
> unsigned char CH59;
> }BYT;
> }ATD_BUF2;
>
> // BUFFER for ROW 3 READING
> union{
> unsigned char BUF[60];
> struct{
> unsigned char CH00;
> unsigned char CH01;
> unsigned char CH02;
> unsigned char CH03;
> unsigned char CH04;
> unsigned char CH05;
> unsigned char CH06;
> unsigned char CH07;
> unsigned char CH08;
> unsigned char CH09;
> unsigned char CH10;
> unsigned char CH11;
> unsigned char CH12;
> unsigned char CH13;
> unsigned char CH14;
> unsigned char CH15;
> unsigned char CH16;
> unsigned char CH17;
> unsigned char CH18;
> unsigned char CH19;
> unsigned char CH20;
> unsigned char CH21;
> unsigned char CH22;
> unsigned char CH23;
> unsigned char CH24;
> unsigned char CH25;
> unsigned char CH26;
> unsigned char CH27;
> unsigned char CH28;
> unsigned char CH29;
> unsigned char CH30;
> unsigned char CH31;
> unsigned char CH32;
> unsigned char CH33;
> unsigned char CH34;
> unsigned char CH35;
> unsigned char CH36;
> unsigned char CH37;
> unsigned char CH38;
> unsigned char CH39;
> unsigned char CH40;
> unsigned char CH41;
> unsigned char CH42;
> unsigned char CH43;
> unsigned char CH44;
> unsigned char CH45;
> unsigned char CH46;
> unsigned char CH47;
> unsigned char CH48;
> unsigned char CH49;
> unsigned char CH50;
> unsigned char CH51;
> unsigned char CH52;
> unsigned char CH53;
> unsigned char CH54;
> unsigned char CH55;
> unsigned char CH56;
> unsigned char CH57;
> unsigned char CH58;
> unsigned char CH59;
> }BYT;
> }ATD_BUF3;
>
> unsigned int HMAT_R1 [30];
> unsigned int HMAT_R2 [30];
> unsigned int HMAT_R3 [30];
>
> void FAULT_LOC_CALC(unsigned int OFST1,
> unsigned int OFST2,
> unsigned int OFST3,
> unsigned int THREH_HOLD,
> unsigned char BUF_END
> );
> void HM_AVG_SEND(unsigned int HM_AVG[]);
>
> // Target : M32 Crystal: 11.0592Mhz
>
> void port_init(void)
> {
>
> DDRABCD=0xFF;
> PORTA=PORTB=PORTC=PORTD=0xFF;
> }
>
> //UART0 initialize
> // desired baud rate: 19200
> // actual: baud rate:19200 (0.0%)
> void uart0_init(void)
> {
> UCSRB = 0x00; //disable while setting baud rate
> UCSRA = 0x00;
> UCSRC = BIT(URSEL) | 0x06;
> UBRRL = 0x23; //set baud rate lo //
> UBRRH = 0x00; //set baud rate hi
> UCSRB = 0x18;
> }
> //call this routine to initialize all peripherals
> void init_devices(void)
> {
> port_init();
> uart0_init();
> MCUCR = 0x00;
> GICR = 0x00;
> TIMSK = 0x00;
> }
>
> /*
> unsigned char ReceiveByte(void)
> {
> while(!(UCSRA & BIT(RXC))) ;
> return UDR;
> }*/
>
> void SEND_CHAR_UART(char ch)
> {
> while(!(UCSRA & BIT(UDRE))) ;
> UDR = ch;
> }
>
> void SendStr(const char *ch)
> { while(*ch != 0x00) SEND_CHAR_UART(*ch++);}
> /**/
> void PRINT_ASCII (unsigned char PRNT)
> {
> unsigned char PRN=0;
>
> PRN=PRNT>>4;
> SEND_CHAR_UART(BinToASCII(PRN));
>
> PRN=PRNT&0x0F;
> SEND_CHAR_UART(BinToASCII(PRN));
> }
> //================================> void SpiInit()
> {
> DDRB |= 0xB0; // Set SCK, MOSI & SS as outputs
> PORTB &= 0x5F; // clear bits MOSI, & SCK
> SPCR = 0x53;
> }
> //================================> unsigned char CHAR_SPI1(unsigned char byte)
>
> {
> SPIPORT |= CS;
>
> SPDR = byte;
> while (!(SPSR & 0x80));
> byte = SPDR;
>
> SPIPORT &= ~CS;
> return byte;
> }
>
> //==============================================> // LCD LIB FUNCTION
> //==============================================> //**************************************
> // void Delay_1ms(void)
> //**************************************
> void Delay_1ms(unsigned long Del)
> {
> int i;
> while (Del--)
> { for (i=0;i<2000;i++); }
> }
>
> /*-----------------------*/
> void LCD_CMD ( unsigned char CMD)
> {
> unsigned char MSN, LSN;
> //unsigned int i;
>
> MSN=( CMD>>4);
> LSN=( CMD&0x0f);
>
> CHAR_SPI1(MSN); CHAR_SPI1(MSN|EN); CHAR_SPI1(MSN);
> Delay_1ms(2);
> CHAR_SPI1(LSN); CHAR_SPI1(LSN|EN); CHAR_SPI1(LSN);
> Delay_1ms(2);
>
> return ;
>
> }
> /*-----------------*/
> void LCD_CHAR ( unsigned char CMD)
> {
> unsigned char MSN, LSN;
>
> MSN=( CMD>>4)|RS;
> LSN=( CMD&0x0f)|RS;
>
> CHAR_SPI1(MSN); CHAR_SPI1(MSN|EN); CHAR_SPI1(MSN);
> Delay_1ms(1);
>
> CHAR_SPI1(LSN); CHAR_SPI1(LSN|EN); CHAR_SPI1(LSN);;
> Delay_1ms(1);
> }
> /*----------*/
> void LCD_INIT ( void)
> {
>
> // Delay_1ms(1000);
> //15MSEC is recommed after Reset
>
> LCD_CMD(FSET_8_BIT );
> Delay_1ms(1);
> LCD_CMD(FSET_8_BIT );
> Delay_1ms(1);
> LCD_CMD(FSET_8_BIT );
> Delay_1ms(1);
>
> LCD_CMD(FSET_4_BIT );
> Delay_1ms(1);
> LCD_CMD(FSET_4_LINE ); //
> Delay_1ms(1);
>
> LCD_CMD( FSET_D_OFF ); //
> Delay_1ms(1);
> LCD_CMD(LCD_CLEAR); //
> Delay_1ms(1);
> LCD_CMD(FSET_ENTRY ); //
> Delay_1ms(1);
> LCD_CMD(FSET_D_ON ); //
> Delay_1ms(1);
>
> LCD_CMD( FSET_HOME); //
> Delay_1ms(1);
> LCD_CMD( FSET_CUR_OFF);
> // Delay_1ms(1);
> }
>
> //===============================================> void LCD_Print(char MSG[])
> {
> char MSG_INDEX=0;
> while(MSG[MSG_INDEX]!='\0')
> {
> LCD_CHAR(MSG[MSG_INDEX]);
> MSG_INDEX++;
> }
> }
> //===============================================> void LCD_PRN_POS(unsigned char MSG[],unsigned char POS )
> {
> char MSG_INDEX=0;
> LCD_CMD( POS);
> while(MSG[MSG_INDEX]!='\0')
> {
> LCD_CHAR(MSG[MSG_INDEX]);
> MSG_INDEX++;
> }
> }
>
> //===============================================> void LCD_Position(unsigned char pos)
> {
> LCD_CMD(pos);
>
> }
> /***************LCD_PrintUI***********************/
> void LCD_PrintUI(unsigned char pos,unsigned int i)
> {
> pos+=5;
> while(i>0)
> {
> LCD_Position(pos);
> LCD_CHAR((i%10)+0x30);
> pos--;
> i/;
> }
> }
> //===============================================================>
> void READ_ADC_ROW1 (void)
> {
>
> ATD_BUF1.BYT.CH00 C_DATH; ATD_BUF1.BYT.CH01
> C_DATL;
> ATD_BUF1.BYT.CH02 C_DATH; ATD_BUF1.BYT.CH03 C_DATL;
> ATD_BUF1.BYT.CH04 C_DATH; ATD_BUF1.BYT.CH05
> C_DATL;
> ATD_BUF1.BYT.CH06 C_DATH; ATD_BUF1.BYT.CH07
> C_DATL;
> ATD_BUF1.BYT.CH08 C_DATH; ATD_BUF1.BYT.CH09
> C_DATL;
>
> //10 rdS
> ATD_BUF1.BYT.CH10 C_DATH; ATD_BUF1.BYT.CH11
> C_DATL;
> ATD_BUF1.BYT.CH12 C_DATH; ATD_BUF1.BYT.CH13
> C_DATL;
> ATD_BUF1.BYT.CH14 C_DATH; ATD_BUF1.BYT.CH15
> C_DATL;
> ATD_BUF1.BYT.CH16 C_DATH; ATD_BUF1.BYT.CH17
> C_DATL;
> ATD_BUF1.BYT.CH18 C_DATH; ATD_BUF1.BYT.CH19
> C_DATL;
> // 20 RDS
> ATD_BUF1.BYT.CH20 C_DATH; ATD_BUF1.BYT.CH21
> C_DATL;
> ATD_BUF1.BYT.CH22 C_DATH; ATD_BUF1.BYT.CH23
> C_DATL;
> ATD_BUF1.BYT.CH24 C_DATH; ATD_BUF1.BYT.CH25
> C_DATL;
> ATD_BUF1.BYT.CH26 C_DATH; ATD_BUF1.BYT.CH27
> C_DATL;
> ATD_BUF1.BYT.CH28 C_DATH; ATD_BUF1.BYT.CH29
> C_DATL;
> // 30 RDS
> ATD_BUF1.BYT.CH30 C_DATH; ATD_BUF1.BYT.CH31
> C_DATL;
> ATD_BUF1.BYT.CH32 C_DATH; ATD_BUF1.BYT.CH33
> C_DATL;
> ATD_BUF1.BYT.CH34 C_DATH; ATD_BUF1.BYT.CH35
> C_DATL;
> ATD_BUF1.BYT.CH36 C_DATH; ATD_BUF1.BYT.CH37
> C_DATL;
> ATD_BUF1.BYT.CH38 C_DATH; ATD_BUF1.BYT.CH39
> C_DATL;
> //40 rds
>
> ATD_BUF1.BYT.CH40 C_DATH; ATD_BUF1.BYT.CH41
> C_DATL;
> ATD_BUF1.BYT.CH42 C_DATH; ATD_BUF1.BYT.CH43
> C_DATL;
> ATD_BUF1.BYT.CH44 C_DATH; ATD_BUF1.BYT.CH45
> C_DATL;
> ATD_BUF1.BYT.CH46 C_DATH; ATD_BUF1.BYT.CH47
> C_DATL;
> ATD_BUF1.BYT.CH48 C_DATH; ATD_BUF1.BYT.CH49
> C_DATL;
> //50 rds
> /* ATD_BUF1.BYT.CH50 C_DATH; ATD_BUF1.BYT.CH51
> C_DATL;
> ATD_BUF1.BYT.CH52 C_DATH; ATD_BUF1.BYT.CH53
> C_DATL;
> ATD_BUF1.BYT.CH54 C_DATH; ATD_BUF1.BYT.CH55
> C_DATL;
> ATD_BUF1.BYT.CH56 C_DATH; ATD_BUF1.BYT.CH57
> C_DATL;
> ATD_BUF1.BYT.CH58 C_DATH; ATD_BUF1.BYT.CH59
> C_DATL;
> */
>
> }
>
> //===============================================> void READ_ADC_ROW2 (void)
> {
>
> ATD_BUF2.BYT.CH00 C_DATH; ATD_BUF2.BYT.CH01
> C_DATL;
> ATD_BUF2.BYT.CH02 C_DATH; ATD_BUF2.BYT.CH03 C_DATL;
> ATD_BUF2.BYT.CH04 C_DATH; ATD_BUF2.BYT.CH05
> C_DATL;
> ATD_BUF2.BYT.CH06 C_DATH; ATD_BUF2.BYT.CH07
> C_DATL;
> ATD_BUF2.BYT.CH08 C_DATH; ATD_BUF2.BYT.CH09
> C_DATL;
>
> //10 rdS
> ATD_BUF2.BYT.CH10 C_DATH; ATD_BUF2.BYT.CH11
> C_DATL;
> ATD_BUF2.BYT.CH12 C_DATH; ATD_BUF2.BYT.CH13
> C_DATL;
> ATD_BUF2.BYT.CH14 C_DATH; ATD_BUF2.BYT.CH15
> C_DATL;
> ATD_BUF2.BYT.CH16 C_DATH; ATD_BUF2.BYT.CH17
> C_DATL;
> ATD_BUF2.BYT.CH18 C_DATH; ATD_BUF2.BYT.CH19
> C_DATL;
> // 20 RDS
> ATD_BUF2.BYT.CH20 C_DATH; ATD_BUF2.BYT.CH21
> C_DATL;
> ATD_BUF2.BYT.CH22 C_DATH; ATD_BUF2.BYT.CH23
> C_DATL;
> ATD_BUF2.BYT.CH24 C_DATH; ATD_BUF2.BYT.CH25
> C_DATL;
> ATD_BUF2.BYT.CH26 C_DATH; ATD_BUF2.BYT.CH27
> C_DATL;
> ATD_BUF2.BYT.CH28 C_DATH; ATD_BUF2.BYT.CH29
> C_DATL;
> // 30 RDS
> ATD_BUF2.BYT.CH30 C_DATH; ATD_BUF2.BYT.CH31
> C_DATL;
> ATD_BUF2.BYT.CH32 C_DATH; ATD_BUF2.BYT.CH33
> C_DATL;
> ATD_BUF2.BYT.CH34 C_DATH; ATD_BUF2.BYT.CH35
> C_DATL;
> ATD_BUF2.BYT.CH36 C_DATH; ATD_BUF2.BYT.CH37
> C_DATL;
> ATD_BUF2.BYT.CH38 C_DATH; ATD_BUF2.BYT.CH39
> C_DATL;
> //40 rds
>
> ATD_BUF2.BYT.CH40 C_DATH; ATD_BUF2.BYT.CH41
> C_DATL;
> ATD_BUF2.BYT.CH42 C_DATH; ATD_BUF2.BYT.CH43
> C_DATL;
> ATD_BUF2.BYT.CH44 C_DATH; ATD_BUF2.BYT.CH45
> C_DATL;
> ATD_BUF2.BYT.CH46 C_DATH; ATD_BUF2.BYT.CH47
> C_DATL;
> ATD_BUF2.BYT.CH48 C_DATH; ATD_BUF2.BYT.CH49
> C_DATL;
> //50 rds
> /* ATD_BUF2.BYT.CH50 C_DATH; ATD_BUF2.BYT.CH51
> C_DATL;
> ATD_BUF2.BYT.CH52 C_DATH; ATD_BUF2.BYT.CH53
> C_DATL;
> ATD_BUF2.BYT.CH54 C_DATH; ATD_BUF2.BYT.CH55
> C_DATL;
> ATD_BUF2.BYT.CH56 C_DATH; ATD_BUF2.BYT.CH57
> C_DATL;
> ATD_BUF2.BYT.CH58 C_DATH; ATD_BUF2.BYT.CH59
> C_DATL;
> */
>
> }
> //=================================================>
> void READ_ADC_ROW3 (void)
> {
>
> ATD_BUF3.BYT.CH00 C_DATH; ATD_BUF3.BYT.CH01
> C_DATL;
> ATD_BUF3.BYT.CH02 C_DATH; ATD_BUF3.BYT.CH03 C_DATL;
> ATD_BUF3.BYT.CH04 C_DATH; ATD_BUF3.BYT.CH05
> C_DATL;
> ATD_BUF3.BYT.CH06 C_DATH; ATD_BUF3.BYT.CH07
> C_DATL;
> ATD_BUF3.BYT.CH08 C_DATH; ATD_BUF3.BYT.CH09
> C_DATL;
>
> //10 rdS
> ATD_BUF3.BYT.CH10 C_DATH; ATD_BUF3.BYT.CH11
> C_DATL;
> ATD_BUF3.BYT.CH12 C_DATH; ATD_BUF3.BYT.CH13
> C_DATL;
> ATD_BUF3.BYT.CH14 C_DATH; ATD_BUF3.BYT.CH15
> C_DATL;
> ATD_BUF3.BYT.CH16 C_DATH; ATD_BUF3.BYT.CH17
> C_DATL;
> ATD_BUF3.BYT.CH18 C_DATH; ATD_BUF3.BYT.CH19
> C_DATL;
> // 20 RDS
> ATD_BUF3.BYT.CH20 C_DATH; ATD_BUF3.BYT.CH21
> C_DATL;
> ATD_BUF3.BYT.CH22 C_DATH; ATD_BUF3.BYT.CH23
> C_DATL;
> ATD_BUF3.BYT.CH24 C_DATH; ATD_BUF3.BYT.CH25
> C_DATL;
> ATD_BUF3.BYT.CH26 C_DATH; ATD_BUF3.BYT.CH27
> C_DATL;
> ATD_BUF3.BYT.CH28 C_DATH; ATD_BUF3.BYT.CH29
> C_DATL;
> // 30 RDS
> ATD_BUF3.BYT.CH30 C_DATH; ATD_BUF3.BYT.CH31
> C_DATL;
> ATD_BUF3.BYT.CH32 C_DATH; ATD_BUF3.BYT.CH33
> C_DATL;
> ATD_BUF3.BYT.CH34 C_DATH; ATD_BUF3.BYT.CH35
> C_DATL;
> ATD_BUF3.BYT.CH36 C_DATH; ATD_BUF3.BYT.CH37
> C_DATL;
> ATD_BUF3.BYT.CH38 C_DATH; ATD_BUF3.BYT.CH39
> C_DATL;
> //40 rds
>
> ATD_BUF3.BYT.CH40 C_DATH; ATD_BUF3.BYT.CH41
> C_DATL;
> ATD_BUF3.BYT.CH42 C_DATH; ATD_BUF3.BYT.CH43
> C_DATL;
> ATD_BUF3.BYT.CH44 C_DATH; ATD_BUF3.BYT.CH45
> C_DATL;
> ATD_BUF3.BYT.CH46 C_DATH; ATD_BUF3.BYT.CH47
> C_DATL;
> ATD_BUF3.BYT.CH48 C_DATH; ATD_BUF3.BYT.CH49
> C_DATL;
> //50 rds
> /* ATD_BUF3.BYT.CH50 C_DATH; ATD_BUF3.BYT.CH51
> C_DATL;
> ATD_BUF3.BYT.CH52 C_DATH; ATD_BUF3.BYT.CH53
> C_DATL;
> ATD_BUF3.BYT.CH54 C_DATH; ATD_BUF3.BYT.CH55
> C_DATL;
> ATD_BUF3.BYT.CH56 C_DATH; ATD_BUF3.BYT.CH57
> C_DATL;
> ATD_BUF3.BYT.CH58 C_DATH; ATD_BUF3.BYT.CH59
> C_DATL;
> */
>
> }
> //=================================> void SEND_ADC_BUFFER( unsigned char BUF[])
> {
>
> unsigned char BUF_PTR;
>
> SEND_CHAR_UART('@');
> for (BUF_PTR=0;BUF_PTR<50;BUF_PTR=BUF_PTR+2)
> {
> SEND_CHAR_UART(BUF[BUF_PTR]&0X0F);
> SEND_CHAR_UART(BUF[BUF_PTR+1]);
>
> }
>
> }
>
> //=================================> void SEND_HMAT( unsigned int BUF[])
> {
>
> unsigned char BUF_PTR;
>
> SEND_CHAR_UART('@');
>
> for (BUF_PTR=0;BUF_PTR<25; BUF_PTR++)
> {
> SEND_CHAR_UART(BYTEHIGH(BUF[BUF_PTR]));
> SEND_CHAR_UART(BYTELOW(BUF[BUF_PTR]));
>
> }
>
> }
>
> volatile unsigned char PW_OPT=0;
> volatile unsigned char STATUS=0;
> volatile unsigned char SCR=0;
>
> //====================================================> // KEY PROCESS
> unsigned char KEY_PROCESS(unsigned char PW)
> {
>
> unsigned char INPUT=0;
> unsigned char KEY=0;
> unsigned char TEMP=0;
>
> TEMP=PW;
>
> INPUT=PINB; Delay_1ms(50); INPUT=PINB;
>
> INPUT=0x0F&INPUT;
>
> if(INPUT!=0x0F)
> {
> if(INPUT==0x0E) // START
> {
> LCD_CMD(LCD_CLEAR);
> LCD_PRN_POS("Trigger IS SEND
> ",LCD_1LINE);
> STATUS=1;
> }
>
> if(INPUT==0x0D) // F1
> {
> if(TEMP<3)
> TEMP++;
> }
>
> if(INPUT==0x0B) // F2
> {
> if(TEMP>0)
> TEMP--;
> }
>
> if(INPUT==0x07) // F3
> {
> if(SCR==1)
> SCR=0;
> // SEND_CHAR_UART
>
> }
> INPUT = 0;
> //=========================> if(TEMP==0)
> {
> LCD_PRN_POS(" PW = 180nsec ",LCD_4LINE);
> }
> else
> if(TEMP==1)
> {
> LCD_PRN_POS(" PW = 360nsec ",LCD_4LINE);
> }
> else
> if(TEMP==2)
> {
> LCD_PRN_POS(" PW = 540nsec ",LCD_4LINE);
> }
> else
> if(TEMP==3)
> {
> LCD_PRN_POS(" PW = 1.08usec ",LCD_4LINE);
> }
>
> }
> return TEMP;
> }
> //=============================================================> #define ROW10()
> PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//1010
> #define ROW20()
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//011
> #define ROW30()
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//110
>
> //===============================================> // Function to SEND and receive
> // PW_OPT=0 , PW0
> // OFSET1 0*4r0
> // OFSET2 0*3T0
> // OFSET3 0*3T0
>
> void TRIG_RECV_PW0(void)
> {
>
> ROW10(); READ_ADC_ROW1 ();
> ROW10(); READ_ADC_ROW2 ();
> ROW10(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R1);
>
> ROW20(); READ_ADC_ROW1 ();
> ROW20(); READ_ADC_ROW2 ();
> ROW20(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R2);
>
> ROW30(); READ_ADC_ROW1 ();
> ROW30(); READ_ADC_ROW2 ();
> ROW30(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R3);
>
> }
> //=====================================================> #define ROW11()
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//1010
> #define ROW21()
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//011
> #define ROW31()
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA&(~LASER);//110
>
> //===============================================> // Function to SEND and receive
> // PW_OPT=1 , PW60
> // OFSET1 0*760
> // OFSET2 0*50
> // OFSET3 0*50
>
> void TRIG_RECV_PW1(void)
> {
> ROW11(); READ_ADC_ROW1 ();
> ROW11(); READ_ADC_ROW2 ();
> ROW11(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R1);
>
> ROW21(); READ_ADC_ROW1 ();
> ROW21(); READ_ADC_ROW2 ();
> ROW21(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R2);
>
> ROW31(); READ_ADC_ROW1 ();
> ROW31(); READ_ADC_ROW2 ();
> ROW31(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R3);
> }
> //===============================================> // Functions to SEND and receive
> // PW_OPT=2 , PWT0
> // OFSET1 0*1000
> // OFSET2 0*700
> // OFSET3 0**700
> void ROW12(void)//101
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
>
> void ROW22(void) //011
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
>
> void ROW32(void) //110
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
> //==> void TRIG_RECV_PW2(void)
> {
> ROW12(); READ_ADC_ROW1 ();
> ROW12(); READ_ADC_ROW2 ();
> ROW12(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R1);
>
> ROW22(); READ_ADC_ROW1 ();
> ROW22(); READ_ADC_ROW2 ();
> ROW22(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R2);
>
> ROW32(); READ_ADC_ROW1 ();
> ROW32(); READ_ADC_ROW2 ();
> ROW32(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R3);
>
> }
>
> //===============================================> // Functions to SEND and receive
> // PW_OPT=2 , PW80
> // OFSET1 0*19400 nsec
> // OFSET2 0*13#40
> // OFSET3 0*13#40
> void ROW13(void)//101
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
> PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);PORTA=PORTA&(~LASER);
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
>
> void ROW23(void)//011
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
>
> void ROW33(void)//110
> {
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA|LASER;PORTA=PORTA|LASER;PORTA=PORTA|LASER;
> PORTA=PORTA&(~LASER);
> }
>
> void TRIG_RECV_PW3(void)
> {
> ROW13(); READ_ADC_ROW1 ();
> ROW13(); READ_ADC_ROW2 ();
> ROW13(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R1);
>
> ROW23(); READ_ADC_ROW1 ();
> ROW23(); READ_ADC_ROW2 ();
> ROW23(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R2);
>
> ROW33(); READ_ADC_ROW1 ();
> ROW33(); READ_ADC_ROW2 ();
> ROW33(); READ_ADC_ROW3 ();
> HM_AVG_SEND(HMAT_R3);
> }
>
> //========================================> // void HM_AVG_SEND(unsigned int HM_AVG[])
> //=======================================> void HM_AVG_SEND(unsigned int HM_AVG[])
> {
> unsigned char TMP0=0;
> unsigned char TMP1=0;
> for(TMP0=0;TMP0<50;TMP0=TMP0+2)
> {
> BYTEHIGH(HM_AVG[TMP1])> ((ATD_BUF1.BUF[TMP0]&0x0F)+
>
> (ATD_BUF2.BUF[TMP0]&0x0F)+
>
> (ATD_BUF3.BUF[TMP0]&0x0F))/3;
>
> BYTELOW(HM_AVG[TMP1])=((ATD_BUF1.BUF[TMP0+1])+
>
> (ATD_BUF2.BUF[TMP0+1])+
>
> (ATD_BUF3.BUF[TMP0+1]))/3;
> TMP1++;
> }
>
> SEND_ADC_BUFFER(ATD_BUF1.BUF);
> SEND_ADC_BUFFER(ATD_BUF2.BUF);
> SEND_ADC_BUFFER(ATD_BUF3.BUF);
> SEND_HMAT(HM_AVG);
> }
> //=============================================> // void FAULT_LOC_CALC
> //=========================================> void FAULT_LOC_CALC(unsigned int OFST1,
> unsigned int OFST2,
> unsigned int OFST3,
> unsigned int THREH_HOLD,
> unsigned char BUF_END
> )
> {
>
> unsigned char RPTR=0;
> // READ TIME betwenn two consective readings
> unsigned int RD_TIME = 360;
> // SPEED OF LIGHT IN 1USEC on Fiber-optic
> unsigned char FIB_VEL= 200;
>
> float RESULT =0;
> unsigned int S1 =0;
> unsigned int S2 =0;
> unsigned int S3 =0;
> unsigned int S_AVG =0;
>
> for(RPTR=0;RPTR > {
> if(HMAT_R1[RPTR]>THREH_HOLD)
> {
> RESULT= OFST1+(RPTR*RD_TIME);
> RESULT=(RESULT/1000); //t
> S1=RESULT*FIB_VEL; //S
> break;
> }
> }
>
> //SEND_CHAR_UART(BYTEHIGH(S1));SEND_CHAR_UART(BYTELOW(S1));
>
> for(RPTR=0;RPTR > {
> if(HMAT_R2[RPTR]>THREH_HOLD)
> {
> RESULT= OFST2+(RPTR*RD_TIME);;
> RESULT=(RESULT/1000); //t
> S2=RESULT*200; //S
> break;
> }
> }
>
> //SEND_CHAR_UART(BYTEHIGH(S2));SEND_CHAR_UART(BYTELOW(S2));
>
> for(RPTR=0;RPTR > {
> if(HMAT_R3[RPTR]>THREH_HOLD)
> {
> RESULT= OFST3+(RPTR*RD_TIME);
> RESULT=(RESULT/1000); //t
> S3=RESULT*200; //S
> break;
> }
> }
> //SEND_CHAR_UART(BYTEHIGH(S3));SEND_CHAR_UART(BYTELOW(S3));
>
> S_AVG=((S1+S2+S3)/3)/2;
>
> /*SEND_CHAR_UART(BYTEHIGH(S_AVG));
> SEND_CHAR_UART(BYTELOW(S_AVG)); */
>
> LCD_CMD(LCD_CLEAR);
> LCD_PRN_POS("FAULT PLACE AT ",LCD_1LINE);
> LCD_PrintUI(LCD_2LINE+3,S_AVG);
> LCD_PRN_POS("METER ",LCD_2LINE+10);
> LCD_PRN_POS("F3 : NEW OBSERVATION ",LCD_4LINE);
>
> }
> /*---*/
> /* ************************************************************************
> *\
> Function: 'main()'.
> \* ************************************************************************
> */
>
> void main(void)
> {
>
> init_devices(); // set the baudrate to 19,200 bps
> using a 14.7456MHz crystal.
> Delay_1ms(100);
> //LASER & DATA BUS DIRECTION SET
> PORTC=0x0;
> PORTA=0xF0;
> DDRC=0x0; // ALL PORTC IS INPUT for ADC_0-7
> DDRAA&0xF0;// Upper Nibble of PORT id INPUT for ADC_8-11
> DDRAA|0x20;// PORTA_BIT5 =LASER as OUTPUT
> PORTA=PORTA&(~LASER);
>
> //============================> SpiInit();
> SPCR = 0x50;SPSR |=0x01;
> LCD_INIT();
> //============================>
> // STARTING LCD SCREEN
> LCD_CMD(LCD_CLEAR);
> LCD_PRN_POS("OPTICAL LOOP TESTER",LCD_1LINE);
> LCD_PRN_POS(" Syndicate #: 25",LCD_2LINE);
> LCD_PRN_POS("TE-43C :Samia, Maria ",LCD_3LINE);
> LCD_PRN_POS(" Saad, Asad ",LCD_4LINE);
> Delay_1ms(1000);
> LCD_CMD(LCD_CLEAR); LCD_CMD(LCD_CLEAR);
> /*-------------*/
>
> while (1) // Now do this forever.
> {
> PW_OPT=KEY_PROCESS(PW_OPT);
> if(SCR==0)
> {
> LCD_CMD(LCD_CLEAR);
> LCD_PRN_POS("START: SEND PULSES ",LCD_1LINE);
> LCD_PRN_POS("F1: Pulse Width + ",LCD_2LINE);
> LCD_PRN_POS("F2: Pulse Width -",LCD_3LINE);
> LCD_PRN_POS(" PW = 180nsec ",LCD_4LINE);
> SCR=1;
> }
> //START STATUS
> if(STATUS==1)
> {
>
> if(PW_OPT==0)
> {
> TRIG_RECV_PW0();
> //Testing FAKE VALUES
> // HMAT_R1[11]%50; HMAT_R2[12](00;
> HMAT_R3[13]!50;
> FAULT_LOC_CALC(720,540,540,2048,25);
>
> }
> // OPTION 1 PW 60;
> if(PW_OPT==1)
> {
> TRIG_RECV_PW1();
> //Testing FAKE VALUES
> //HMAT_R1[6]%50; HMAT_R2[8](00; HMAT_R3[7]!50;
> FAULT_LOC_CALC(1260,900,900,2048,25);
> }
> // OPTION 1 PW T0;
> if(PW_OPT==2)
> {
> TRIG_RECV_PW2();
>
> //Testing FAKE VALUES
> //HMAT_R1[11]%50; HMAT_R2[14](00;
> HMAT_R3[13]!50;
> FAULT_LOC_CALC(1800,1200,1200,2048,25);
> }
>
> // OPTION 1 PW 80;
> if(PW_OPT==3)
> {
> TRIG_RECV_PW3();
> //Testing FAKE VALUES
> HMAT_R1[11]%50; HMAT_R2[14](00;
> HMAT_R3[13]!50;
> FAULT_LOC_CALC(3400,2300,2300,2048,25);
> }
>
> PW_OPT=0;
> STATUS=0;
> }
> //END STATUS
> }
> //while 1
> } // main
>
> Hi
> >I am new to DSP kit and we are implementing our final year degree project
> on it. I am facing some of very basic issues.
> >
> >C6713 is little endain by default. We have to interface emif data pins
> with AD9220 (ADC) 12 bit with bit 1(MSB) and bit 12(LSB). There are 32 data
> pins on the emif connector. But the confusion is that which pins should be
> interfaced with the ADC pin 0 to pin 11 or pin 20 to pin 31.
> >
> >Secondly the 3 LEDs taht blink when the DSK is turned on, are no more
> blinkly, they just stay off. I think because of this our project does not
> build properly. Is there any way it can be fixed??
> >
> >Help will be highly appreciated
> >Regards
> >samz
> >
> >_____________________________________
> >
> >
>
>
> _____________________________________
>
--
www.dsprelated.com/blogs-1/nf/Mike_Dunn.php