DAVE Code. I need some help to under stand this

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi! I want o understand the following Code. Can you explain me Please? I am new to dave:(


#include //Declarations from DAVE Code Generation (includes SFR declaration)

uint8_t expired;
uint32_t DutyCycle;
XMC_VADC_RESULT_SIZE_t result;


void timer()
{
expired=1;
}

void delay(uint32_t us)
{

uint32_t TimerId;
TimerId = (uint32_t)SYSTIMER_CreateTimer(us,SYSTIMER_MODE_PERIODIC,(void*)timer,NULL);
if (TimerId != 0U)
{
expired=0;
SYSTIMER_StartTimer(TimerId);
while(expired==0)
{}
SYSTIMER_StopTimer(TimerId);
SYSTIMER_DeleteTimer(TimerId);
}

}

int main(void)
{
DAVE_Init();


while(1U)
{
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);

result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_0);


if(result >= 2000)
{
//control servo
PWM_SetDutyCycle(&PWM_0,270);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result >=1000 && result <= 2000)
{
PWM_SetDutyCycle(&PWM_0,400);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result < 1000)
{
PWM_SetDutyCycle(&PWM_0,750);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
}
}
0 Likes
1 Reply
User13353
Level 1
Level 1
What exactly is it you don't understand?

To get started, you should read the API documentation of the DAVE Apps you are using:
1. Move your cursor to an ADC_MEASUREMENT_*, PWM_*, or SYSTIMER_* function.
2. Hit [F3].
3. A new editor tab should open and show the declaration of the function with the accompanying docstring.

Another way is to select the app in DAVE's "APP Dependency" view and press [ALT]+[F3].
This fires up Windows' Help viewer showing the App's documentation generated from the docstrings.

HTH
0 Likes