Pumpkin, Inc.

Pumpkin User Forums

Problems using Timer and OS_Delay

For issues specific to TI's MSP430 line of ultra-low-power microcontrollers, including compilers (e.g. Quadravox AQ430), IDEs (e.g. IAR Embedded Workbench) and development tools (e.g. TI MSP-FET430 Flash Emulation Tool).

Problems using Timer and OS_Delay

Postby Syed Akbar » Tue Nov 08, 2005 7:21 am

Hello Aek,

In my Salvo program, i have two tasks. and 1 binary semaphore. Task1 is the highest priority task. But Task1 can be run only when a timer with 20ms(50Hz) expires. Task1 will signal task2. Based on tutorial5, i have used the following timer.
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
CCR0 += 10000;
OSTimer();
}
It is explained that this is 10ms system timer. therefore for 20ms i have used
OS_Delay(2,acb302_conversion_label);
I have used this statement in the task1 at the end after signalling binary semaphore.

As per the general rule, it shld context switch and the task2 which is waiting the semaphore shld run. Unfortuntely, it breaks here without going to the next task.

Hopefully, you followed the description. Can you please elucidate me what can be the problem. I shall provide with further details, if you require any.

Thank you very much
-Syed Akbar

------------------
Akbar

Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany

Re: Problems using Timer and OS_Delay

Postby aek » Tue Nov 08, 2005 8:24 am

You appear to be doing things right -- can you post the entire main.c so I can see your tasks?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Problems using Timer and OS_Delay

Postby aek » Wed Nov 09, 2005 6:52 am

Hello Syed.

The problem is that you have not created infinite loops inside your tasks. What you need is e.g.

code:
void acb302_conversion(void)
{
while (1)
{
start_conv_acb302(); // Starts ADC10 Conversion
ACB302_conv(); // Starts conversions
OSSignalBinSem(BINSEM1_P);
OS_Delay(2,acb302_conversion_label); // delays the task by 2*10ms= 20ms(50Hz)
}
}

Without these infinite loops, program execution "falls out" of each task at the end, and the program's behavior is undefined.

------------------

[This message has been edited by aek (edited November 09, 2005).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Problems using Timer and OS_Delay

Postby Syed Akbar » Wed Nov 09, 2005 10:39 am

Thank you very much. My problem is solved.
-Syed Akbar
Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany

Re: Problems using Timer and OS_Delay

Postby Syed Akbar » Wed Nov 09, 2005 12:42 pm

Thank you very much. I am hereby posting my main.c I have used some functions from an Assembly program using the concept of mixing C and Assembly.
- Syed Akbar

code:
#include <main.h>
#include <salvo.h>
#include <msp430x12x2.h>
#include "mytypes.h" // My own things...

const UINT32 BoardID0 @ 0xE000 = 0x01234567;
const UINT32 BoardID1 @ 0xE004 = 0x89abcdef;

// declarations for functions used from ACB302_1.s43
extern void init_acb302(void);
extern void start_conv_acb302(void);
extern void ACB302_conv(void);
extern void ACB302_vektorbetrag(void);

#define TASK_ACB302_CONVERSION OSTCBP(1) // Task 1 definition
#define TASK_RESULTANT_VECTOR OSTCBP(2) // Task 2 definition
//#define TASK_DISPLAY_VIBRATIONS OSTCBP(3) // Task 3 definition


#define BINSEM1_P OSECBP(1) // Event 1: Binary Semaphore


#define PRIO_ACB302_CONVERSION 1 // Priority of Task 1
#define PRIO_RESULTANT_VECTOR 2 // Priority of Task 2
//#define PRIO_DISPLAY_VIBRATIONS 3 // Priority of Task 3


_OSLabel(acb302_conversion_label) // Task 1 label for context switch
_OSLabel(resultant_vector_label) // Task 2 label for context switch
//_OSLabel(display_vibrations_label) // Task 3 label for context switch

//////////////////////////////////////////////////////////////
// Name: Set_DCO
// Description: Sets the DCO and controls speed using TimerA SW FLL
// Parameter: -
// Returns: -
//////////////////////////////////////////////////////////////
void Set_DCO (void) // Set DCO to selected frequency
{
#define DELTA 977 // target DCO= DELTA*(4096) = 4Mhz
//#define DELTA 900 // target DCO = DELTA*(4096) = 3686400
//#define DELTA 256 // target DCO = DELTA*(4096) = 1048576
//#define DELTA 70 // target DCO = DELTA*(4096) = 286720
unsigned int Compare, Oldcapture = 0;

BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8
CCTL2 = CM_1 + CCIS_1 + CAP; // CAP, ACLK
TACTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, cont-mode, clear

while (1)
{
while (!(CCIFG & CCTL2)); // Wait until capture occured
CCTL2 &= ~CCIFG; // Capture occured, clear flag
Compare = CCR2; // Get current captured SMCLK
Compare = Compare - Oldcapture; // SMCLK difference
Oldcapture = CCR2; // Save current captured SMCLK

if (DELTA == Compare) break; // If equal, leave "while(1)"
else if (DELTA < Compare) // DCO is too fast, slow it down
{
DCOCTL--;
if (DCOCTL == 0xFF)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3)))
BCSCTL1--; // Did DCO roll under?, Sel lower RSEL
}
}
else
{
DCOCTL++;
if (DCOCTL == 0x00)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x07)))
BCSCTL1++; // Did DCO roll over? Sel higher RSEL
}
}
}
CCTL2 = 0; // Stop CCR2
TACTL = 0; // Stop Timer_A
BCSCTL1 &= ~0x30; // Set ACLK Divider to 0
BCSCTL2 = 0; // MCLK = SMCLK = DCOCLK
}//Set_DCO


void acb302_conversion(void)
{
start_conv_acb302(); // Starts ADC10 Conversion
ACB302_conv(); // Starts conversions
OSSignalBinSem(BINSEM1_P);
OS_Delay(2,acb302_conversion_label); // delays the task by 2*10ms= 20ms(50Hz)

}

void resultant_vector(void)
{
ACB302_vektorbetrag(); // calculates the resultant vector
P1OUT ^= 0x01; // Toggle P1.0 using XOR
OS_WaitBinSem(BINSEM1_P, OSNO_TIMEOUT, resultant_vector_label);
}

//void display_vibrations(void)
//{
//}


//-----------------------------------------------------------------------------------------
void main()
//-----------------------------------------------------------------------------------------
{
Init(); // For Device Initialization
OSInit(); // Initializes all of Salvo's data structures,
// pointers, and counters.
InitPORT(); // Port Initialization

WDTCTL=WDTPW+WDTHOLD; // stop WD

P1OUT = 0x00; // Set P1 to output direction
P1DIR = 0x03;

Set_DCO();

P2DIR |= 0x08; // Turn on Sensor switch
P2OUT |= 0x08;

init_acb302(); // Initializes ACB302 and Enables adc10_irq interrupt function
// which reads x,y and z axes.


// Create Tasks
OSCreateTask(acb302_conversion, TASK_ACB302_CONVERSION, PRIO_ACB302_CONVERSION);
OSCreateTask(resultant_vector, TASK_RESULTANT_VECTOR, PRIO_RESULTANT_VECTOR);
// OSCreateTask(display_vibrations, TASK_DISPLAY_VIBRATIONS,PRIO_DISPLAY_VIBRATIONS);


OSCreateBinSem(BINSEM1_P, 0); // Creates Binary Semaphore
OSEi(); // Enables Interrupts
for(; ;)
OSSched(); // Multitasking
}


// Interrupt Vecator for Timer
// 10ms System Timer at a frequency of 100Hz
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
CCR0 += 10000;
OSTimer();
}



------------------
Akbar

[This message has been edited by aek (edited November 09, 2005).]

Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany


Return to TI's MSP430

Who is online

Users browsing this forum: No registered users and 1 guest

cron