Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic18f43k22 salvo RTOS

Status
Not open for further replies.

bhan1992

Member level 1
Member level 1
Joined
Feb 25, 2012
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,511
im trying to blink an led. the rate which it blink depends on the adc value. i have tested that the adc is working fine. but when i load this piece of code, the led just wont light up at all.
is there any other way of blinking the led depending on the adc value besides this rtos?
Code:
#include <p18f43k22.h>
#include <adc.h>
#include <delays.h>
#include <stdlib.h>
#include <timers.h>
#include <salvo.h>
#undef OSC

int result;

void slow_beep (void);
void medium_beep (void);
void fast_beep (void);
void isr (void);

_OSLabel (_slow_beep)
_OSLabel (_medium_beep)
_OSLabel (_fast_beep)

#pragma code high_vector = 0x08
void interrupt (void)
{
	_asm goto isr _endasm
}
#pragma code
#pragma interrupt isr

void slow_beep (void)
{
	while(result >= 250 && result < 600)
	{
		PORTBbits.RB5 = ~PORTBbits.RB5;
		OS_Delay(65, _slow_beep);	//0.65 seconds
	}
}
void medium_beep (void)
{
	while(result >= 600 && result < 850)
	{
		PORTBbits.RB5 = ~PORTBbits.RB5;
		OS_Delay(45, _medium_beep);	//0.45 seconds
	}
}
void fast_beep (void)
{
	while(result >= 850)
	{
		PORTBbits.RB5 = ~PORTBbits.RB5;
		OS_Delay(25, _fast_beep);	//0.25 seconds
	}
}

void main (void)
{
	TRISB = 0;

	OSCreateTask(slow_beep, OSTCBP(1), 7);
	OSCreateTask(medium_beep, OSTCBP(2), 7);
	OSCreateTask(fast_beep, OSTCBP(3), 7);

	OpenTimer0 (TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_1);
	WriteTimer0(55536);
	INTCONbits.GIE = 1;

	OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_2_TAD, ADC_REF_VDD_VSS, ADC_INT_OFF );

	PORTB = 1;		//initialisation 0.7 second beep
	Delay10KTCYx(10);	
	PORTB = 0;

	while(1)
	{
	SetChanADC(ADC_CH0);
	ConvertADC();
	while(BusyADC());
	result = ReadADC();
	OSSched();
	OS_Delay(10,main)	//delay 0.1 second
	}
	CloseADC();
}

void isr (void)
{
	WriteTimer0(55536);
	OSTimer();	//creating 0.01 second system tick
	INTCONbits.TMR0IF = 0;
}
 

Are you connecting LED in RB5, and I think you have to change the while condition in every task.....

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
void slow_beep (void)
{
    while(1)
    {
    if( result >= 250 && result < 600 )
      {
        PORTBbits.RB5 = ~PORTBbits.RB5;
        OS_Delay(65, _slow_beep);   //0.65 seconds
      }
    }
}


And also i don think blinking LED was three different tasks....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top