-
Reference Code: bubblelogger code from sparkfun website ( http://www.sparkfun.com/tutorial/Bubble … Logger.zip )
-
Referenced LPC 2148 user manual
-
We are trying to timestamp 2 individual pulses with different frequencies using the GPIO pins in Logomatic V2.
We are polling 2 GPIO pins which are receiving ttl pulses (1ms high period) and logging data.
Based on whether 1 or 0 present at each pin, respective counters are incremented and written to file.
output format : gps_count = 00001, imu_count = 00028, rtc_seconds = 00087
gps_count is from GPIO1(pin no. P0,30) and imu_count is from GPIO2(pin no. P0,29). rtc_seconds is the value of RTC timer on LPC2148.
- Operation:
1st pin has a fixed signal at frequency 1Hz
2nd pin can have a frequency anywhere between 10 hz to 100 hz
The value of count for each pin has to be updated everytime a pulse comes in and it should be logged to a file.
- Problem:
This results in the skipping of values or inconsistencies in the data when the frequency of the 2nd signal is increased beyond 10 hz.
We have used simple if/else conditions to check the status of the GPIO pins.
Will the use of fast IO registers alleviate this problem and if so how do you use them?
Please help… We have attached the code we have written below.
Our CODE
int main (void)
{
int rtc_seconds = 0;
int bubble_number = 0;
int gps_count = 0;
int imu_count = 0;
boot_up(); //Init LPC, IO pins, and FAT
log_string("Log started: IMU frequency 25 HZ, 1 RTC_seconds tick interval = 1 ms 1 timer tick = 0.1 ms \r\n");
set_pin_mode(1, "DI");
set_pin_mode(2, "DI");
while(1)
{
if(read_digital_pin(1) == 1 && read_digital_pin(2) == 0)
{
bubble_number++;
gps_count++;
if (bubble_number > 20)
{
char str_data[128];
string_printf(str_data, "1: gps_count = %05d, imu_count = %05d, rtc_seconds = %05d\r\n ", gps_count, imu_count, rtc_seconds );
log_string(str_data);
}
}
else if(read_digital_pin(2) == 1 && read_digital_pin(1) == 1)
{
bubble_number++;
gps_count++;
imu_count++;
if (bubble_number > 20)
{
char str_data[128];
string_printf(str_data, " 3: gps_count = %05d, imu_count = %05d, rtc_seconds = %05d\r\n ", gps_count, imu_count, rtc_seconds );
log_string(str_data);
}
}
else if(read_digital_pin(2) == 1 && read_digital_pin(1) == 0)
{
bubble_number++;
imu_count++;
if (bubble_number > 20)
{
char str_data[128];
string_printf(str_data, " 2: gps_count = %05d, imu_count = %05d, rtc_seconds = %05d\r\n ", gps_count, imu_count, rtc_seconds );
log_string(str_data);
}
}
if(T1TC >10)
{
T1TC -= 10;
rtc_seconds++;
}
}
return 0;
}
void log_string(char *buf)
{
int stringSize = strlen(buf);
fat16_write_file(handle, (unsigned char*)buf, stringSize);
sd_raw_sync();
}
//Sets the state of a digital output
void write_digital_pin(char pin_number, char pin_state)
{
pin_number = look_up_pin(pin_number); //Translate labeled pins to pins on LPC
if(pin_state == 1) //Turn pin on
IOSET0 |= (1<<pin_number);
else //Turn pin off
IOCLR0 |= (1<<pin_number);
}
//Reads the stat of a digital input
char read_digital_pin(char pin_number)
{
pin_number = look_up_pin(pin_number); //Translate labeled pins to pins on LPC
if(IOPIN0 & (1<<pin_number)) return(1); //If pin is high, return a 1
return(0); //else return 0
}
void set_pin_mode(char pin_number, char *buf)
{
pin_number = look_up_pin(pin_number); //Translate labeled pins to pins on LPC
if (buf[0] == 'D') //Digital IO
{
if(pin_number > 15) //Then we are in PINSEL1 register
{
pin_number -= 16;
PINSEL1 = (PINSEL1 & ~(3<<(pin_number*2))); //Clear the bits to force GPIO function
}
else
PINSEL0 = (PINSEL0 & ~(3<<(pin_number*2))); //Clear the bits to force GPIO function
}
if (buf[1] == 'I') //Input
IODIR0 &= ~(1<<pin_number); //Set pin as input
if (buf[1] == 'O') //Output
IODIR0 |= (1<<pin_number); //Set pin as output
}