This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LM4f120H5QR problems with a ultrasound sensor



Hi people. Me and other three friends are working for a contest and we try to program a ultrasound sensor, but we have some problems.

CODE:

#define PART_LM4F120H5QR 1

#include "lm4f120h5qr.h"

#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"

double distance=0;
long val_Wtimer2=0;
bool flag_sensor=0;

void WTimer2IntHandler(void)
{
TimerIntClear(WTIMER2_BASE,TIMER_CAPA_EVENT);
val_Wtimer2 = TimerValueGet(WTIMER2_BASE,TIMER_A);
flag_senzor=1;
TimerDisable(WTIMER2_BASE,TIMER_CAPA_EVENT);
}

inline void sent_Trigger()
{
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0xFF);
TimerEnable(WTIMER2_BASE,TIMER_A);
SysCtlDelay(20);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0x00);
}

void init_WTimer2()
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER2);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinConfigure(GPIO_PD0_WT2CCP0);
GPIOPinTypeTimer(GPIO_PORTD_BASE,GPIO_PIN_0);

TimerConfigure(WTIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP); //////
TimerControlEvent(WTIMER2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);

TimerIntRegister(WTIMER2_BASE,TIMER_A,WTimer2IntHandler);
TimerIntEnable(WTIMER2_BASE,TIMER_CAPA_EVENT);
//IntEnable()

}

void main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 );
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);

init_WTimer2();

IntMasterEnable();

while(1)
{
if(flag_sensor)
{
distance=((val_Wtimer2 * 0.0000000125 ) * 341.0)/2.0;

flag_sensor=0;
}

SysCtlDelay(40000000);

sent_Trigger();
}
}

 

the problem is that the val_Wtimer2 give to us some strange values.

Can samebody help me and my friends too?

  • edi edi said:
    Me and other three friends are working for a contest

    So I hope you will be sharing your prize with forum contributors, then?

    edi edi said:
    val_Wtimer2 give to us some strange values

    In what way, "strange"?

    What values were you expecting?

    What values did you actually get?

    What debugging have you done in order to explain the discrepancy?

    What did you find?

    Debugging tips:

    http://www.8052.com/faqs/120313

    http://www.eetimes.com/discussion/break-point/4027526/Developing-a-good-bedside-manner?pageNumber=0

     

     

  • "Gang of four's" certain Verify Answer (in quad) likely motivates such interest.. 

    (wide timer set-up/config sprang from my answering response - when "gang" was one - never acknowledged)  Caveat Venditor...

  • i want to measure a distance with wide timer 1 in input edge timer mode. the timer start counting after we send a pulse to the sensor with start counting and stop when a positive edge.

    after we made a new version of code and use a prescaler (65535) and the timer have always similar values (val_Wtimer=4 294 930 687)  the last three digits are the only one who change and this happen at the same distance. 

       the formula for distance: distance = (val_Wtimer * 0.0000000125 * 65535.0 * 341.0 ) / 2.0 for a 80mhz frequence and the distance is in metres

  • sorry   i use wide timer 2

  • Might the use of 16 bit prescaler reduce/obscure the effectiveness of your wide timer?

    Value you show is very close to full 32 bit capacity of WTimer.  Have you earlier "over-flowed" the WTimer - necessitating your introduction of prescaler?

    When you test your device - at a known, fixed distance - what typical pulse width does your scope show/record?  Have you then cut the distance in half - repeated that test - and judged your sensor to be proper?