CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

voltage and delay problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

voltage and delay problem
PostPosted: Sun Oct 23, 2005 2:01 am     Reply with quote

HI Dear all
Crying or Very sad
I work with 16F877 PIC .My problem is when I programed the PIC to give 8 square wave signals at frequency 50HZ with different delay between each others .when I checked by oscilloscope the frequency and delay ware not as I programed and the peak voltage was 2.5 volt so please tell me what is the problem .
Exclamation
regardes
[/code]
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sun Oct 23, 2005 2:38 am     Reply with quote

Do you have anything connected to the pin? How much current are you sinking fom the pin? There might be something holding the line down, like a relatively small resistance connected between the pin and ground. The resistance could be a solder bridge.
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 23, 2005 3:00 am     Reply with quote

thank u for replay . there is nothing conected with bin i just measure directly from the bin by the oscilloscope and waht about the wrong on the frequency i use delay function and use delay with speed 20000000
asmallri



Joined: 12 Aug 2004
Posts: 1630
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Oct 23, 2005 3:14 am     Reply with quote

Anonymous wrote:
thank u for replay . there is nothing conected with bin i just measure directly from the bin by the oscilloscope and waht about the wrong on the frequency i use delay function and use delay with speed 20000000


Post your code. If you want to get accurate waveforms you might want to setup timers instead of using the delay routines.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 23, 2005 3:17 am     Reply with quote

thank u for ur response i will send my code to you now
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 23, 2005 8:26 am     Reply with quote

[/****************************************************
* *
* COPYRIGHT (c) safoan *
* *
* codes = Chasing signal *
* *
* KIT = emBox-877 Kit ( CPU = PIC16F877A ) *
* *
* STATUS = DONE 12/09/05 *
* *
****************************************************/
#include <16F877A.h>

#FUSES HS,NOWDT,NOPROTECT,NOPUT

#USE DELAY( CLOCK=20000000 )

#byte port_a=5 /* define the address of PORTA */

#byte port_b=6 /* define the Address of PORTB */

#byte port_c=7 /* define the address of PORTC */

#byte port_d=8 /* define the address of PORTD */


static byte CONST UP_MAP[8] = { 0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff };

static byte CONST DOWN_MAP[8] = { 0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00 };

static byte CONST delay_v[8] = { 365,1145,998,950,950,998,1145,365 };


/***************************************
* LED wiring *
* ********** *
* 8 signals = PB0 - PB7 *
* 8 signals = PD0 - PD7 *
***************************************
* NOTE: see emBox-877 schematic *
***************************************/


main(){


char cnt,tnt;

/* long asof;*/

/* set_tris_a(0xfe); */ /* set port_a to be RA0 outputs */

set_tris_b(0); /* set port_b to be ALL outputs */

/* set_tris_c(0xbf); */ /* set port_c to be RC6 outputs */

set_tris_d(0); /* set port_d to be ALL outputs */



/* tnt = 0 ; */ /* intialize counter tnt */


port_b = 0 , /* initialize & turn off ALL PORTB outputs */


/* port_c =0; */ /* initialize & turn off ALL PORTC outputs */


port_d = 0xff; /* initialize & turn on ALL PORTD outputs */



for(;;){ /* forever loop*/


/* if(tnt == 80)


tnt = 0 ;


if (tnt % 2 == 0) */ /* multiplixer condition selector */


/* port_a = 0x01, port_c=0;


else port_c = 0x40, port_a=0;*/


DELAY_US (delay_v[0]) ;


for (cnt=0 ; cnt < 4 ; cnt++) { /* delay loop for the first H-bridge leg (positive cycle) */


port_b = UP_MAP[cnt],

/* pick value to display from array */
port_d = 0xff - UP_MAP[cnt];


if (cnt==3)


DELAY_US(3084);


else DELAY_US(delay_v[cnt]+1); } /* delay time loop for increment stage (positive cycle)*/


for( cnt=4 ; cnt < 8 ; cnt++ ){ /* delay time loop for decrement stage (positive cycle) */


port_b = UP_MAP[cnt] ,


port_d = 0xff - UP_MAP[cnt];


DELAY_US ( delay_v[cnt] ) ; }


/* if(tnt == 80)


tnt = 0 ;


if ( tnt % 2 == 0 )


port_c = 0x40 ,


port_a = 0x01 ;


else port_c = 0 ,


port_a = 0 ;


tnt++ ;*/


DELAY_US( delay_v[7] );


for (cnt=0 ; cnt < 4 ; cnt++) { /* delay time loop for increment stage (negative cycle) */


port_b = DOWN_MAP[cnt] ,

port_d = 0xff - DOWN_MAP[cnt];


if (cnt==3)


DELAY_US(3084);


else DELAY_US(delay_v[cnt+1]);}


for (cnt=4 ;cnt < 8; cnt++){ /* delay time loop for decrement stage(negative cycle) */


port_b = DOWN_MAP[cnt],

port_d = 0xff - DOWN_MAP[cnt];


DELAY_US( delay_v[cnt] );

}


}
}





][/code]
Ttelmah
Guest







PostPosted: Sun Oct 23, 2005 10:37 am     Reply with quote

First, when you post code, use the 'code' button, otherwise it is almost unreadable to us.
Second remove 'remmed' out lines which also make the program flow almost unreadable.
Comments though, on the glaring faults. A _variable_ used in a delay statement can only be an integer. Hence 255 max.
Even if this was not the case, you are trying to store values over 255, into an integer variable.
Your delays will be completely screwed.
On the 2.5v question, double check that your scope is set to the range you think it is, and try a simple test, just toggle a line high/low, with no other code. Also note that you should be disabling the peripherals that exist on some of the IO pins being used, or may get unexpected results. Look at the typical initialisations used on code posted, or use the wizard (which will generate some unecessary initialisation, it will show the sort of extras needed.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 23, 2005 3:52 pm     Reply with quote

Quote:
Even if this was not the case, you are trying to store values over 255, into an integer variable.

To further explain, both a byte and and int are unsigned 8 bit variables for CCS. You would have to use int16 or long to hold a 16bit variable. The delay statements only allow constants for 16 bit numbers. Even though your arrays are constants, accessing them and using that value for the delay is not allowed.
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 24, 2005 12:01 am     Reply with quote

when i cahange the defination of matrix also there is no cahnge Crying or Very sad I put long and int16b even float there is no change
Ttelmah
Guest







PostPosted: Mon Oct 24, 2005 2:24 am     Reply with quote

trento wrote:
when i cahange the defination of matrix also there is no cahnge Crying or Very sad I put long and int16b even float there is no change

There won't be.
You are still missing part of the 'point'. The 'delay' functions, _only_ accept int8 values, when handed a value from a 'variable'. Though the contents of your matrix are themselves filled with constants, by passing these through an array, you are using a variable. You are still trying to use a value that the function does not support.
Given you only have a limited number of values to select, you can use this approach instead:
Code:

switch (cnt) {
case 0:
    delay_us(366);
    break;
case 1:
    delay_us(1146);
    break;
case 2:
    delay_us(999);
    break;
case 3:
    delay_us(951);
    break;
case 4:
    delay_us(951);
    break;
case 5:
    delay_us(999);
    break;
case 6:
    delay_us(1146);
    break;
case 6:
    delay_us(366);
    break;
}

Now I have added one to each delay value (which is what you are doing in this line):
DELAY_US(delay_v[cnt]+1);

This will actually be faster than getting the value from the array, and then incrementing this anyway.
However you also need to be aware that operations take time, and that there will be quite a few clock cycles added to the timings, whichever approach you use.

Best Wishes
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 24, 2005 4:00 am     Reply with quote

thank you so much for your care I tried your suggestion it work properly .

But I want to use the matrix because I want to store groupe of delay

angle sets.Depending on the feedback ,one of the sets will excute I do

single phase induction motor control using PIC this programe just one

set of angle Crying or Very sad from my program please tell how I can do it .

regards.
Ttelmah
Guest







PostPosted: Mon Oct 24, 2005 6:55 am     Reply with quote

Write your own delay function that accepts a larger variable. You don't say how fast the processor is running, which will affect both the accuracy, and limitations on this. You could also consider using the CCP, to give a much more accurate result. If you run timer2, so it has the longest period you require, then you can program the CCP, to the period you require, clear it's interrupt flag, and just 'poll' this till it changes, to get accurate timings.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 24, 2005 6:56 am     Reply with quote

How accurate do the delays need to be?
You will most likely need to write you own delay routines or wrap the built in delay routine inside your own function. You could put a delay_us(256) inside a for loop and execute it multiple times. Each time subtracting 256 from your delay value until the value is less than 256 and then call one final delay with the result. Keep in mind that loops and conditional tests take time so you can adjust for this by delaying less than 256 to compensate for the added overhead of the loop.
trento



Joined: 14 Oct 2005
Posts: 26

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 24, 2005 9:12 am     Reply with quote

Thank u so much it was very good hints thank you for your help Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 24, 2005 9:24 am     Reply with quote

Quote:
You could put a delay_us(256) inside a for loop and execute it multiple
times. Each time subtracting 256 from your delay value until the value is
less than 256 and then call one final delay with the result. Keep in mind
that loops and conditional tests take time so you can adjust for this by
delaying less than 256 to compensate for the added overhead of the loop.
http://www.ccsinfo.com/forum/viewtopic.php?t=16656&highlight=longdelayus
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group