コード例 #1
0
ファイル: equal.c プロジェクト: eugenecartwright/hthreads
void setup_timer( void )
{
    Huint data;
    Huint delta;
    Huint timer1;
    Huint timer2;
    Huint timer3;

    printf( "Setting up Timer\n" );
    
    timer_set_delta( 0,  5 * DELTA );
    delta = timer_get_delta( 0 );
    
    timer_set_data( 0, 0xCAFEBABE );
    data = timer_get_data( 0 );
    
    timer_set_command( 0,   HT_TIMER_CMD_PERIODIC   |
                            HT_TIMER_CMD_ENABLE     |
                            HT_TIMER_CMD_LOAD       |
                            HT_TIMER_CMD_RUN        );

    timer1 = timer_get_value( 0 );
    timer2 = timer_get_value( 0 );
    timer3 = timer_get_value( 0 );
    
    printf( "Timer Delta:    %u\n", delta );
    printf( "Timer Data:     %#08x\n", data );
    printf( "Timer Value 1:  %#08x\n", timer1 );
    printf( "Timer Value 2:  %#08x\n", timer2 );
    printf( "Timer Value 3:  %#08x\n", timer3 );
    
    timer_set_delta( 0, DELTA );
    timer_set_command( 0,   HT_TIMER_CMD_PERIODIC   |
                            HT_TIMER_CMD_ENABLE     |
                            HT_TIMER_CMD_LOAD       |
                            HT_TIMER_CMD_RUN        );
}
コード例 #2
0
ファイル: piezo.c プロジェクト: NexusIF/ProjectsBackup
/**
 * \fn void beep_low_ms(uint16_t ms)
 * \brief Generate 2Khz sine signal for x miliseconds.
 * \param ms Number of miliseconds.
 * */
void beep_low_ms(uint16_t ms)
{
    uint32_t count = ((uint32_t)ms*1000)/50;
    uint16_t counter = 50;
    uint32_t i;


    timer_reset();

    for(i=0; i<count; i++)
    {
        DAC_SetChannel2Data(DAC_Align_12b_R, sine_samples[sine_samples_index]);

        while(abs_diff(counter,timer_get_value())<50) {}
        counter+=50;

        sine_samples_index++;
        if(sine_samples_index==SINE_SAMPLES_COUNT) sine_samples_index = 0;
    }
}