Monk666
Joined: 25 Oct 2008 Posts: 2
|
Gyro data Acquisition in Timer interruption |
Posted: Wed Dec 10, 2008 11:22 am |
|
|
Gyro data Acquisition in Timer interrupt:
I try use the KamPutty's code for LIS3LV02DQ(Gyro) in interrupt for every 50ns.
When I use KamPutty's code
http://forum.sparkfun.com/viewtopic.php?p=18666)
alone it worked just fine.
But when I put those code in Timer interruption, it wouldn't work any
more, and the receiving data just stuck at the same number and never change.
Does anyone knowing what happened?
Code: |
void main()
{
setup_spi(FALSE);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_2 );
setup_ccp2 ( CCP_COMPARE_INT ); // configure CCP2 in COMPARE mode and ...
// CCP2 Interrupt on compare match
enable_interrupts ( INT_CCP2 );
set_timer1(0);
CCP_2=ccp2_period; // start the CCP2_ISR at 1 msec later
setup_adc_ports(AN0_TO_AN1|VSS_VDD);
setup_adc ( ADC_CLOCK_DIV_32 ); // 32 * T_osc = 1.6 us per bit at 20 MHz
set_adc_channel ( 0 ); // select RA0 as analog input channel
enable_interrupts ( GLOBAL );
delay_us(100);
write_16bit_serial_data(0x20, 0b11000111); //原始設定是+-2G
write_16bit_serial_data(0x21, 0b00000001);
printf("Who Am I = %d\n\r", read_8bit_serial_data(0x0f));
delay_ms(1000);
while ( 1 )
{
while ( !kbhit() ) // press any key to get out
{
delay_ms ( 200 ); // wait 200 msec
//printf("\r\n T= %lu.%04lu sec, AN0= %lu, yout=%f ", time_sec, time_tick, ad_data, yout );
//printf("\r\n T= %lu.%04lu sec, AN0= %lu ", time_sec, time_tick, ad_data);
//printf("\r\n Test variable for e_previous=%f", e_previous );
//printf("\r\n Test variable for x_acc=%lu y_acc=%lu z_acc=%lu", X,Y,Z);
//printf("\r\n Test variable for y_acc=%lu", y_acc);
//printf("\r\n Test variable for max_duty=%lu", max_duty );
//printf("\r\n Test variable for duty_set=%lu", duty_set );
printf("\r\n Test =%lu", test);
//printf("\n\n\r ",);
};
} |
|
|