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.

problem with Switch case statement in ccs c

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
hello very body I am reading a frequency of a square wave and took decisions accordingly,but my coding are not operating can you plz help me to solve the issue;solution is appreciable:
see some of my codes below:

function with switch case:
float kagabo(void)
{
switch(period)
{

case 100: period=160;
printf(lcd_putc,"\150%%");
delay_ms(2000);
break;
case 13:printf(lcd_putc,"\f16%%");
delay_ms(2000);
break;

case 14:printf(lcd_putc,"\f15%%");
delay_ms(2000);
break;


case 15:printf(lcd_putc,"\f14%%");
delay_ms(2000);
break;


case 16: printf(lcd_putc,"\f13%%");
break;

case 17: printf(lcd_putc,"\f12%%");
delay_ms(2000);
break;


case 18: printf(lcd_putc,"\f19%%");
delay_ms(2000);
break;

case 19: period=10;
printf(lcd_putc,"\f200%%");
delay_ms(2000);
break;
}
}

CCP1 stups:
setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1
enable_interrupts(INT_CCP1); // Setup interrupt on risining edge
enable_interrupts(GLOBAL);
output_low(PIN_B4);

Switch button which has to be activated for reading values in kagabo function from switch case statement:
if(input(PIN_C4)==0)
{

//kagaba();
tempdisplay();
kagabo();
if (input(PIN_C4)==0)//&&(period<100))
{
delay_ms(100);
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(1200);

printf(lcd_putc "\12%%");

delay_ms(1000);
}
}
 

I can't help with CCS directly but where is your interrupt routine and do you really need all those delays? Delays used in code measuring an input period can cause the edges to be missed.

Brian.
 

I can't help with CCS directly but where is your interrupt routine and do you really need all those delays? Delays used in code measuring an input period can cause the edges to be missed.

Brian.
hello my interrupts codes are here:

#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
flag=0;
}
}
How can I proceed with all thoses delays??How may I reduce them?


after the above;do you have any idea of how I can proceed for measuring sinusoidal wave?
 

I'm not familiar with CCS but shouldn't there be a line in the ISR to clear the interrupt bit?

The real issues with the delays is what are they there for anyway? You seem to have long delays all over your program that don't do anything.

There are varius ways of measuring sine waves, I presume you mean their frequency and not amplitude. The easiest is simply to feed the sine wave to a comparator to turn it into a square wave then measure it in the way you are at the moment. You can also do it by sampling with an ADC but the math gets much more complicated.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top