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.

Using Timers in the SYS-BIOS: ... question writing to console from SWI/HWI // HOW ?

I have a GPIO port reading in values from a couple pins (either high or low read). The way that the device attatched to the gpio pins works is:

1. Set the pins high for a couple microseconds to charge the cap on the device.

2. Read the pins after a couple hundred microseconds to read the values as high or low.

In the sys-bios I used the clock function to do this by setting a period of a couple hundred microseconds and making an instance calling the function to read the values.  .... (then in the function I called  sysctldelay() to wait a couple micro-seconds for the charging of the cap before exiting ).  

This process worked fine. But now I would like to do the same thing with two timers so I setup in Sys-bios two timers on two different clocks and defined their period.  Then I attached both timers to two different functions, set the timers to start when called by user, and then set them to a one-time shot timer.  The two functions work like so:

function on first timer does it's thing, clears it's interupt then enables second timer.... 

function on second timer does it's thing, clears it's interrupt then enables first timer... 

... and this should keep going on 

I figured I could enable one of the timers from outside of these two functions with TimerEnable(arg0,arg1) and the timer would start and the two functions would keep enabling the different timers until I dissable both of them later (haven't figured that part out yet).

My problem is that the timers don't start at all.  I believe it's part that I'm starting the timers on my own because if I setup the timers to start on start up they run.  What is the problem here?

_____________________________________________________________________________________

Secondly, Is there a way to print from a HWI or SWI to the console.  I've read the documentation about not being able to use system_printf() but don't understand what I could use in replacement. 

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

Also, one other question.  I wanted to put my h files in a seperate folder to clean up the working folder a bit.  I went through adding the folder to my "includes" folder and shows up in there but it doesn't seem to work.  I've done some hunting on this and can't find the answer.  How would I do this?

  • Hi Antonio,

    Can you show me how you did the includes? Both in options (path) and in the code?

    First, if you don't need the 2 timers running at the same time you can simple use one of them, you can change the period on the first one and start it up.

    Now the problem,did you try setting just 1 timer in one shot mode? Did it work?

    I am not sure but you seem to want to set up the timers without configuring them first and instead, start them and configure them after?

    Could you please provide the code in which you configure and enable the timers?

  • To try to add a folder called myHfiles that contains all my H files I went to project--> properties -->> include options then added a folder (top box).

    Reading http://www.ti.com/lit/ug/spmu298a/spmu298a.pdf there is a TimerLoadSet() function that does what I believe you are saying I could use to use only one timer. 

    Yes, I did set them up in one shot mode and also setup as "will be started by user" 

    As far as configuring them.  I've setup the clock in another function (doing PWM) so I do not need to re-set that up.  As far as setting up the timer  I was under the impression that the config file did that for you.  If you look at example 6 and 7 in the training lab ( http://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/TI_RTOS_Workshop/TI_RTOS_Kernel_Workshop_Student_Guide_rev2.20.pdf ) the way it is done there is that the timer runs off a configured system clock and the timer is setup in the hardwareInit() function... IE:

    void hardware_init(void)
    {
    	uint32_t ui32Period;
    
    	//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
    	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    	// ADD Tiva-C GPIO setup - enables port, sets pins 1-3 (RGB) pins for output
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    
    	// Turn on the LED
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);
    
    	// Timer 2 setup code
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);			// enable Timer 2 periph clks
    	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);		// cfg Timer 2 mode - periodic
    
    	ui32Period = (SysCtlClockGet() /2);						// period = CPU clk div 2 (500ms)
    	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period);			// set Timer 2 period
    
    	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);		// enables Timer 2 to interrupt CPU
    
    	TimerEnable(TIMER2_BASE, TIMER_A);						// enable Timer 2
    
    }
    

    Then a HWI was setup in the sys-bios with the VECTOR # using the timer configured above.  

    I was under the impression that using the Sys-bios to configure a timer this hardware init was mainly done for you.

    IE: TimerConifigure() and TimerLoadSet() were done by the cfg on bootup  and setting it to be started by user calling TimerEnable() starts the timer.

    Also, in doing this the functions the timer calls in the sys-bios were HWI's automatically so there is no need to set them up as HWI's. 

    actually looking at the lab manual I posted above and looking at the optional lab for lab 7 this is exactly what they did... they replaced all the code above with the timer module in Sys-bios without the HWI.  I can do this, but I cannot start the timer from my code by calling the TimerEnable() function with the timer name.  This is my problem. 

  • For future searchers.  The way I got around the problems I was experiencing....

    1.  First of all.. I cheated an used one timer.  I used SysCtrDelay(800); in the ISR to wait 10us while the port was charged.

    2.  To get around the problem I was having enabling the timer when I checked "user will enable timer" in the sys-bios was to set that setting to "timer starts on startup" and disabling the timer immediately upon start.  Then when I want to use the timer I started the timer (in periodic mode).  Works fine that way.

    I've continued to be stumped by the Timer on the TIVA C.  There are many ways to configure the timers but the sys-bios GUI screen only allows you to set a couple of settings.  For example:  if you want to setup an edge-trigger timer (like I want to do now)  I have no options for that in Sys-BIOS.  I've run into the issue of setting up an edge-trigger timer and getting an "error in HWI" if I use Sys-Bios.  I have further research to do but it seems that the Timer moduls in the BIOS are more use-full and configurable outside of the BIOS.  

    My next step is to use sys-bios with an idle thread or Clock-Controlled TASK .. and in that TASK use a Timer with edge trigger interrupt that is configured within the Task.... then see if I have problems with this.

    Anyway,  I'm going to post another thread about the edge-trigger timers.  Hopefully someone found this post useful.

  • sorry about not replying back. I got too busy with studies and then i forgot about this :/

    Glad you got it fixed, and thank you for sharing the solution