Dear Community.
I am implementing oneWire timing in RTOS environment. My problem is how to implement precise timing? The board I am using is TivaC launchpad. You know in 1Wire the uC needs to issue different timing slots for reading and writing bits.
// Delay values in usec unit
#define OW_A_DELAY 6
#define OW_B_DELAY 64
#define OW_C_DELAY 60
#define OW_D_DELAY 10
#define OW_E_DELAY 9
#define OW_F_DELAY 55
#define OW_G_DELAY 0
#define OW_H_DELAY 480
#define OW_I_DELAY 70
#define OW_J_DELAY 410
Seaching for reliable answer and tried most of them without success.
but I need a little help to get my code more efficient:
Here is my code:
static void DELAY_us(uint32_t usec) { uint32_t end; uint32_t start = Timestamp_get32(); Float target = (Float)usec / OW_USEC_PER_CYCLE; Float result; while(1) { end = Timestamp_get32(); result = end-start; if( result >= target ) { result = result; break; } } }
Sometimes the function provides accurate timing but sometimes doesn't. The result is much more greater than target.
However I have a much more bigger problem this one.
There are my function for 1Wire:
//-------------------------------------------------------------------------- // Setting this bit to 0 drives the 1-Wire line low static void OW_SetLineLow() { GPIOPinTypeGPIOOutput(OW_PORT,OW_PIN); GPIOPinWrite(OW_PORT,OW_PIN,false); //GPIO_setAsOutputPin(OW_PORT,OW_PIN); //GPIO_setOutputLowOnPin(OW_PORT,OW_PIN); } //-------------------------------------------------------------------------- // Setting the bit to 1 releases the 1-Wire to be pulled up by resistor or pulled down by a 1-Wire device static void OW_SetLineRelease() { GPIOPinTypeGPIOInput(OW_PORT,OW_PIN); }
The commented statements were used in MSP430, and works very fast. The issue with above function is the execution time. Changing the GPIO direction takes so long. About 5usec or more. I did not realize such long execution with MSP430.
Is there any more efficient way in RTOS?
Update: For precise timing I have create a Timer in RTOS and toggled a LED in SWI to measure the accuracy of the timer. It was very accurate as I expected, however when I post a Semaphore to start the execution of the blocked task, ( and toggle the LED in the task) it was very very inaccurate. This timing advice was found in the forum.
I think I am using something wrong. Please point me to the right direction to solve this timing problem.
Thank you very much.