avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Newbie question (Solved)


From: David VanHorn
Subject: Re: [avr-gcc-list] Newbie question (Solved)
Date: Thu, 26 Feb 2009 20:03:04 -0500


 
Well, I thought I should report back on my attempt to read these sensors.
I got past my sampling problem.
It's not pretty, but it works.
 
In my T0 ISR, where I do mS timers, I have it sampling the inputs, using T1 to count the period of four cycles of each input.
 
//*********************************************************************************************
//
// Timer 0 overflow ISR
//
// 1mS timer maintainance, and sampling of the two magnetometer channels.
//
// WARNING: If either mag input stops, the app will hang!
//
ISR(TIMER0_OVF_vect)
{
 TCNT0 = T0_Reload_Value;    // Needed to hit 1mS ticks.
 if (0 < LCD_Timer) LCD_Timer--;  // Dec the pacing timer to 0
 
 if (Raw_Samples > Raw_Data_Size) { // If the raw data buffer isn't full
  TCCR1B &= ~(1<<CS10);   // Stop T1
  TCNT1=0;      // Clear T1
 
  // Use this when simulating.
  /*
  Raw_Data[0][Raw_Data_In_Index] = 0xAA;
  Raw_Data[0][Raw_Data_In_Index++] = 0x55;
  if ((Raw_Samples - 1) < Raw_Data_In_Index ) Raw_Data_In_Index = 0;
  Raw_Data_Size++;
  return;
  */
 
 
  // Sync to the A channel
  while (PIND & 0x04);   // Wait for a low, so we know we're not seeing a high level yet
  while (!(PIND & 0x04));   // Wait for the high edge
  TCCR1B |=(1<<CS10);    // START the clock to T1
 
  // T1 is now counting the pulse width.
  // Since it can be as short as 5uS, we'll count four cycles.
  // That can be as little as 20us (4 cycles = 80 counts)
  // or as much as 92 uS (4 cycles = 368 counts)
 
  // So we can check with the scope.
  //Debug_DDR |= (1 << Debug_Pin); // Output
  //Debug_Port |= (1 << Debug_Pin); // High
 
  while (PIND & 0x04);    // Wait for a low on PD2
  while (!(PIND & 0x04));    // Wait for a high on PD2 One cycle has gone
  while (PIND & 0x04);
  while (!(PIND & 0x04));    // Now two
  while (PIND & 0x04);
  while (!(PIND & 0x04));    // Now three
  while (PIND & 0x04);
  while (!(PIND & 0x04));    // Now four
  TCCR1B &= ~(1<<CS10);    // Stop T1

  //Debug_Port &= ~(1 << Debug_Pin); // Low
  Raw_Data[0][Raw_Data_In_Index] = TCNT1; // Save the value but do NOT bump the pointer yet
  TCNT1=0;      // Clear T1

  // Sync to the B channel, and proceed as above
  while (PIND & 0x08);
  while (!(PIND & 0x08));
  TCCR1B |=(1<<CS10);
  while (PIND & 0x08);
  while (!(PIND & 0x08));
  while (PIND & 0x08);
  while (!(PIND & 0x08));
  while (PIND & 0x08);
  while (!(PIND & 0x08));
  while (PIND & 0x08);
  while (!(PIND & 0x08));
  TCCR1B &= ~(1<<CS10);
  Raw_Data[1][Raw_Data_In_Index++] = TCNT1; // Save the value and bump the pointer 
  if ((Raw_Samples - 1) < Raw_Data_In_Index ) Raw_Data_In_Index = 0;
  Raw_Data_Size++;
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]