Exemple #1
0
void DBG_testUltraDistance(S_robot*r, uint32_t reps)
{

    uint32_t period = 100;
    uint32_t prStart = _tic();
    S_sensor_ultra* u = 0;
    u = r->ults.u[0];
    while(reps>1)
    {
        CLOCK_digiPrint(r);

        if( _tocFrom(prStart) > period )
        {
            gpio_toggle(PLED,LEDBLUE3);
            LCD_gotoxy(r->lcd,0,0);
            fprintf(r->flcd, "=%0.5f|s=%u",  u->dist, u->state  );
            LCD_gotoxy(r->lcd,0,1);
            fprintf(r->flcd, "=%6lu |p=%u ",  u->nTicks, u->nOwerflow);
            //fprintf(r->flcd, "[s=%u][%4u]", u->state, cnt);

            //cnt = timer_get_counter(u->TIMX);
            prStart = _tic();
        }
        reps--;
    }
Exemple #2
0
int main (void)
{

	DIO_init();

	LCD_init();
	LCD_gotoxy(1,1);
	printf("AVR ADC Tutorial");
	LCD_gotoxy(1,2);

	ADC_init();
	ADC_Configure_Reference(VREFERENCE_VALUE);
	ADC_Configure_PRESCALAR(PRESCALAR_VALUE);
	ADC_Enable();
	ADC_start();

	while(1)
	{
		LCD_gotoxy(1,2);
		adc_read=ADC_read_8bits(ADC0);
		printf("%d",adc_read);
		printf ("                  " );
		TO_DELAY(500);
	}

	return(0);

}
Exemple #3
0
void DBG_testActuators_wInit(S_robot*r, uint32_t reps)
{
    uint32_t period = 100;
    uint32_t prStart = _tic();
    uint8_t q=0;
    //uint32_t ocval = 0;
    //init
     rcc_clock_setup_in_hse_8mhz_out_72mhz();

     /* enable GPIOC clock */
     rcc_periph_clock_enable(RCC_GPIOC);

     /*
      * set GPIO12 at PORTC (led) to 'output alternate function push-pull'.
      */
    // gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);

    gpio_mode_setup(GPIOA,GPIO_MODE_AF,GPIO_PUPD_NONE,GPIO1);
    gpio_set_af(GPIOA,GPIO_AF1,GPIO1);
    uint32_t *p = TIM2_CCMR1;
    *p = 0x6800;
    p = TIM2_CR1 ;
    *p |= 1<<7; // ARPE
    p = TIM2_EGR ;
    *p |= 1<<0;

    p = TIM2_CCER ;
    *p |= 1<<4; //enable output



    while(reps>1)
    {
        CLOCK_digiPrint(r);
        if( _tocFrom(prStart) > period )
        {

            //TIM_CCR1(m->TIMX) = m->OCval;
            //ocval += 10;
            //model_timer_SET_outputCompare(TIM2,TIM_OC2,ocval);

            // printit
            LCD_gotoxy(r->lcd,0,0);
            LCD_gotoxy(r->lcd,0,1);
            //fprintf(r->flcd, "");
                //for(q=0;q<ROB_MOTOR_COUNT;q++)
                    //fprintf(r->flcd, "%.0f%%=%lu/%lu", ds->m[q]->dutyCycle*100, ds->m[q]->OCval, ds->m[q]->tim_s->period );
                    //fprintf(r->flcd, "oc=%lu=%lu", ocval, m->OCval );

            prStart = _tic();

        }
        reps--;
    }
Exemple #4
0
void DBG_testActuators(S_robot*r, uint32_t reps)
{
    uint32_t period = 10;
    uint32_t prStart = _tic();
    uint8_t q=0;
    //uint32_t ocval = 0;

    S_robot_dcmotors* ds = 0;
    ds = &(r->dcs);
    S_actuator_dcmotor* m = 0;
    m = ds->m[q];

    float dcadd = 0.00001;
    mswait(1000);
    while(1)
    {
        CLOCK_digiPrint(r);
        if(m->dutyCycle >= 1.0) m->dutyCycle = 0.0;
        DCMOT_SET_dutyCycle(m, m->dutyCycle+dcadd);
    }
    while(reps>1)
    {
        CLOCK_digiPrint(r);
        if( _tocFrom(prStart) > period )
        {

            // cycle dutyCycle
            if(m->dutyCycle >= 1.0) m->dutyCycle = 0.0;

            DCMOT_SET_dutyCycle(m, m->dutyCycle+0.02);

            TIM_CCR1(m->TIMX) = m->OCval;
            //ocval += 10;
            //model_timer_SET_outputCompare(TIM2,TIM_OC2,ocval);

            // printit
            LCD_gotoxy(r->lcd,0,0);
                    fprintf(r->flcd, "%.0f%%", ds->m[q]->dutyCycle*100);
            LCD_gotoxy(r->lcd,0,1);
            //fprintf(r->flcd, "");
                //for(q=0;q<ROB_MOTOR_COUNT;q++)
                    fprintf(r->flcd, "%lu/%lu|", ds->m[q]->OCval, ds->m[q]->tim_s->period );
                    //fprintf(r->flcd, "oc=%lu=%lu", ocval, m->OCval );

            prStart = _tic();

        }
        reps--;
    }
    gpio_toggle(PLED,LEDORANGE1);
Exemple #5
0
void DBG_testButtonState(S_robot* r, uint32_t repeats,uint32_t ms)
{
    while(repeats>1)
    {
        repeats--;
        S_robot_buttons * b = &(r->btns);

        REFRESH_buttonState(b->bStart);
        REFRESH_buttonState(b->bLine);
        REFRESH_buttonState(b->bSumo);
        gpio_clear(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3);

        LCD_clear(r->lcd);
        LCD_gotoxy(r->lcd,0,0);
        fprintf(R.flcd, "%x|%x|%x",
                b->bStart->state,
                b->bLine->state,
                b->bSumo->state
                 );

        if(b->bStart->state) gpio_set(PLED,LEDGREEN0);
        if(b->bLine->state) gpio_set(PLED,LEDBLUE3);
        if(b->bSumo->state) gpio_set(PLED,LEDRED2);
        mswait(ms);
    }
    gpio_clear(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3);
Exemple #6
0
void DBG_testAllUltraDistance(S_robot*r, uint32_t reps)
{

    uint32_t period = 100;
    uint32_t prStart = _tic();
    uint8_t q=0;
    S_robot_ultras* us = 0;
    us = &(r->ults);
    while(reps>1)
    {
        CLOCK_digiPrint(r);

        if( _tocFrom(prStart) > period )
        {
            gpio_toggle(PLED,LEDBLUE3);
            LCD_gotoxy(r->lcd,0,0);
            fprintf(r->flcd, "s");
                for(q=0;q<ROB_ULTRA_COUNT;q++)
                    fprintf(r->flcd, "%u", us->u[q]->state );
            fprintf(r->flcd, "p");
                for(q=0;q<ROB_ULTRA_COUNT;q++)
                    fprintf(r->flcd, "%u", us->u[q]->nOwerflow);
            fprintf(r->flcd, "  ");
            //fprintf(r->flcd, "p=");
            //u->nOwerflow

            LCD_gotoxy(r->lcd,0,1);
            //fprintf(r->flcd, "a");
                for(q=0;q<ROB_ULTRA_COUNT;q++)
                {
                    fprintf(r->flcd, "%3.0f|", us->u[q]->dist );
                    //fprintf(r->flcd, "%3.0f", us->u[q]->dist );
                    //if(q<3) fprintf(r->flcd, "|");
                }

            //fprintf(r->flcd, "[s=%u][%4u]", u->state, cnt);

            //cnt = timer_get_counter(u->TIMX);
            prStart = _tic();
        }
        reps--;
    }
Exemple #7
0
void vLCDTask( void *pvParameters )
{
xLCDMessage xMessage;

	/* Initialise the LCD and display a startup message. */
	LCD_init();
	LCD_cur_off();
    LCD_cls();
    LCD_gotoxy( 1, 1 );
    LCD_puts( ( signed char * ) "www.FreeRTOS.org" );

	for( ;; )
	{
		/* Wait for a message to arrive that requires displaying. */
		while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );

		/* Display the message.  Print each message to a different position. */
		LCD_cls();
		LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
		LCD_puts( xMessage.pcMessage );
	}

}
Exemple #8
0
void CLOCK_digiPrint(S_robot* r)
{
    static uint32_t world_time = 0;
    static uint32_t last_wtime = 0;
    world_time = _tic()/1000;
    if(world_time != last_wtime)
    {
        char str_hhmmss[] = "%2lu:%02lu:%02lu";
        char str_mss[] = "%2lu:%02lu";
        char str_s[] = "%2lu";
        uint32_t hh = (world_time/3600);
        uint32_t mm = (world_time/60)%60;
        uint32_t ss = world_time%60;
        if(mm > 0)
        {
            if(hh>0)
            {
                LCD_gotoxy(r->lcd,8,0);
                fprintf(r->flcd, str_hhmmss, hh, mm, ss);
            }
            else
            {
                LCD_gotoxy(r->lcd,11,0);
                fprintf(r->flcd, str_mss, mm, ss);
            }
        }
        else
        {
            LCD_gotoxy(r->lcd,14,0);
            fprintf(r->flcd, str_s, ss);

        }
        last_wtime = world_time;
    }
Exemple #9
0
/*---------------------------------------------------------------------------*/
static void lcd (char *str)
{
  short wStrLen;
  lcd_setup_t LCDMessage;
  extern xQueueHandle xLCDQueue;

  LCDMessage.byColumn = 0;
  wStrLen = strlen("lcd ");
  if (strlen(str) > wStrLen) {
    LCD_cls();
    LCD_gotoxy(1, 1);
    LCDMessage.Message = &str[wStrLen];
    xQueueSend(xLCDQueue, &LCDMessage, portMAX_DELAY);
    shell_output("LCD OK!", "");
    shell_output("Message: ", LCDMessage.Message);
  } else {
    shell_output("LCD ERROR: String null!", "");
  }
}
Exemple #10
0
void temp_show() {
    LCD_clear();
    LCD_puts("    SET TEMP    ");
    LCD_gotoxy(1, 2);

    LCD_puts("<");
    if (m_dayTemp != 0) {
        if (m_dayTemp >= 10) {
            LCD_putint(m_dayTemp, 10);
        } else {
            LCD_puts("0");
            LCD_putint(m_dayTemp, 10);
        }
    } else {
        LCD_puts("00");
    }

    LCD_puts(" / ");

    if (m_nightTemp != 0) {
        if (m_nightTemp >= 10) {
            LCD_putint(m_nightTemp, 10);
        } else {
            LCD_puts("0");
            LCD_putint(m_nightTemp, 10);
        }
    } else {
        LCD_puts("00");
    }

    LCD_puts(" +- ");

    if (m_offsetTemp != 0) {
        LCD_putint(m_offsetTemp, 10);
    } else {
        LCD_puts("0");
    }

    LCD_puts(" C>");
//	LCD_puts("<00 / 00 +- 0 C>");
}
Exemple #11
0
static void vCheckTask( void *pvParameters )
{
portBASE_TYPE xErrorOccurred = pdFALSE;
TickType_t xLastExecutionTime;
unsigned portBASE_TYPE uxColumn = 0;
xLCDMessage xMessage;

	xLastExecutionTime = xTaskGetTickCount();

	xMessage.xColumn = 0;
	xMessage.pcMessage = "PASS";

    for( ;; )
	{
		/* Perform this check every mainCHECK_DELAY milliseconds. */
		vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );

		/* Has an error been found in any task? */

        if( xAreBlockingQueuesStillRunning() != pdTRUE )
		{
			xErrorOccurred = pdTRUE;
		}

		if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
		{
			xErrorOccurred = pdTRUE;
		}

        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
        {
            xErrorOccurred = pdTRUE;
        }

        if( xArePollingQueuesStillRunning() != pdTRUE )
        {
            xErrorOccurred = pdTRUE;
        }

        if( xIsCreateTaskStillRunning() != pdTRUE )
        {
            xErrorOccurred = pdTRUE;
        }

        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
        {
            xErrorOccurred = pdTRUE;
        }

        LCD_cls();
        xMessage.xColumn++;
        LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );

        if( xErrorOccurred == pdTRUE )
        {
            xMessage.pcMessage = "FAIL";
        }

		/* Send the message to the LCD gatekeeper for display. */
		xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
	}
}
Exemple #12
0
void set_temp_init(void) {
    u16 value;
    u08 step = 0, empty, tmp[2];
    u08 day[3], month[3], year[5];
    u08 temp1[3], temp2[3];
    u08 skipLoop = 0;

    LCD_write_command(0x0f);
    waitms(20);
    do {
        empty = 0;
        LCD_gotoxy((2 + step), 2);
        value = decode_rc5();
        switch (value) {
            case KEY_0: {
                LCD_puts("0");
                strcpy(tmp, "0");
                break;
            }

            case KEY_1: {
                LCD_puts("1");
                strcpy(tmp, "1");
                break;
            }

            case KEY_2: {
                LCD_puts("2");
                strcpy(tmp, "2");
                break;
            }

            case KEY_3: {
                LCD_puts("3");
                strcpy(tmp, "3");
                break;
            }
            case KEY_4: {
                LCD_puts("4");
                strcpy(tmp, "4");
                break;
            }
            case KEY_5: {
                LCD_puts("5");
                strcpy(tmp, "5");
                break;
            }

            case KEY_6: {
                LCD_puts("6");
                strcpy(tmp, "6");
                break;
            }

            case KEY_7: {
                LCD_puts("7");
                strcpy(tmp, "7");
                break;
            }

            case KEY_8: {
                LCD_puts("8");
                strcpy(tmp, "8");
                break;
            }

            case KEY_9: {
                LCD_puts("9");
                strcpy(tmp, "9");
                break;
            }

            case KEY_LEFT: {
                if (step == 5) {
                    step -= 4;
                } else if (step == 11) {
                    step -= 5;
                } else {
                    step--;
                }
                skipLoop = 1;
                break;
            }

            case KEY_RIGHT: {
                empty = 1;
                break;
            }

            default: {
                step--;
                empty = 1;
                break;
            }
        }

        if(skipLoop) {
            skipLoop = 0;
            continue;
        }

        if (!empty) {
            switch (step) {

                case 0:
                    strcpy(temp1, tmp);
                    break;
                case 1:
                    strcat(temp1, tmp);
                    break;

                case 5:
                    strcpy(temp2, tmp);
                    break;
                case 6:
                    strcat(temp2, tmp);
                    break;
                default:
                    break;
            }
        }
        step++;
        if (step == 2)
            step += 3;
        if (step == 7)
            step += 4;
    } while (step <= 11);
    LCD_write_command(0x0C);

    if (m_dayTemp >= 0 && m_nightTemp >= 0) {
        m_requiresSettings |= SETTING_TEMP;
    }

    m_dayTemp = (atoi(temp1) % 90);
    m_nightTemp = (atoi(temp2) % 90);
    m_offsetTemp = (atoi(tmp) % 90);
}