edwardcullen
Junior Member level 3
i wrote a program when i use only sending pulse part, i can excite my sonar module and see the echo on oscilloscope.
when i use my entitre program without SEND pulse part, i can do ADC on any signal And send data on pc perfectly..
but when i use entirte program together i see nothing!!!
i mean my sonar module is not getting excited !!!
below is complete program:
somebody please help...
when i use my entitre program without SEND pulse part, i can do ADC on any signal And send data on pc perfectly..
but when i use entirte program together i see nothing!!!
i mean my sonar module is not getting excited !!!
below is complete program:
somebody please help...
Code:
{
Micro controller: P30F4013 XTx8 + 15 Mhz crystal = 120 Mhz
use string,conversion and uart lib
}
program ADC_Test;
const
TCY = 30000000; // 30MIPS. Make sure you get your OSC correct!
NUM_OF_SAMPLES = 200;
SAMPLE_FREQ = 30000;// 125000;
PRESCALER_1_1 = TCY / SAMPLE_FREQ; // Should be 10,000
var
Samples: array[NUM_OF_SAMPLES] of word; // live data
freq: word; // Auxiliary variables
txt: string[10];
Filled : boolean;
j : byte;
// Number or samples is a global number because ISRs are global
SamplesRead : byte;
while true do // main loop
begin
pulse_out ; // call function pulse sending pulse to start the sonar chip
LATB.0 := 1; // Set PORTB to zero
Delay_us(500);
LATB.0 := not LATB.0; // Invert PORTB value
Delay_ms(5);
put_data_in_array; // call a procedure to put all receve data in a array and set a variable " array_is_full" to true when the array is full
If Array_is_full do // so that dont happens until the array is full and data ready to be send , if that dont happens the if loop is skip and return to pulse_out...
end;
//-------------- Initialization of AD converter
procedure InitAdc();
begin
ADPCFG := 0x00FF; // PORTB<8:15> is analog, PORTB<0:7> is digital
TRISB.8 := 1; // RB8 as input pin( echo pin)
TRISB.0:=0;
ADCHS := 8; // Connect RBxx/ANxx as CH8 input. RB8 is input pin
ADCSSL := 0; //
ADCON3 := 0x0127; // sample time = 31 Tad.
ADCON2 := 0;
ADCON1 := 0x80E0; // Turn ADC ON
end;//~
//-------------- Main Initialization
procedure Init();
begin
// PASCAL initializes all variables to 0 at start
// memset(@Samples, 0, 1024); // Clear samples
InitAdc();
uart1_init(115000); // init usart at max speed
TON_bit := 0; // start timer1
T1CON.B5 := 0; // Timer1 prescaler 1: 1
T1CON.B4 := 0;
PR1 := PRESCALER_1_1;// dword(Get_Fosc_kHz) * 1000 / (4 * SAMPLE_FREQ); //sampling timer period register value = Frequency of operation (Fosc/4) [Hz] / Sampling_Frequency [Hz]
end;
procedure StartAcquire();
begin
IFS0.T1IF := 0; // clear interrupt flag
Filled := false;
SamplesRead := 0; // Start with no samples
TON_bit := 1; // start timer1
IEC0.T1IE := 1; // enable T1 interrupt
end;
//-------------- Takes current sample
{ INLINE this in the ISr to save cycles
function ReadAdc() : word;
begin
// SAMP_bit := 0; // start conversion
SAMP_bit := 1; // start conversion
repeat until (DONE_bit);
result := ADCBUF0; // Get ADC value
end;
}
procedure Timer1Int(); iv IVT_ADDR_T1INTERRUPT;
begin
// Samples[SamplesRead] := ReadAdc();
SAMP_bit := 1; // start conversion
repeat until (DONE_bit);
Samples[SamplesRead] := ADCBUF0; // Get ADC value
if SamplesRead<NUM_OF_SAMPLES-1 then
SamplesRead:=SamplesRead+1
else begin
TON_bit := 0; // stop timer1
IEC0.T1IE := 0; // diable T1 interrupt
Filled := true; // Flag the main loop
end;
IFS0.T1IF := 0; // clear interrupt flag
end;
//-------------- Main program starts here
begin
Init(); // Initialize all
StartAcquire();
while (true) do begin
if Filled then begin
for j := 0 to NUM_OF_SAMPLES-2 do begin
wordtostr(Samples[j],txt);
uart1_write_text(txt + ',');
end;
wordtostr(Samples[NUM_OF_SAMPLES-1],txt);
uart1_write_text(txt + #10 + #13);
StartAcquire();
end;
end;
end.
Report this post