Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution.

Reply
 
LinkBack Thread Tools Display Modes
Old 29th April 2008, 03:09 PM   (permalink)
Default interesting RF project needs a little assistance :)

Hi,
I'm trying to construct a 2 part project that involves a transmitter and a reciever, the transmitter reads 6 analogue inputs and sends the result to the reciever, which then translates this to 6 digipots (using I2C i think).....but at the moment i'm stuck on getting the transmitter to wait for each AD conversion to complete before saving the result for later comparison with the old result...

basically, i need to know how to get my program to wait 20uS.....
i've looked at Wingmax's posts on the subject, but i just cant compile if i #include "delay.h" OR "delay.c"


once i've cracked that i'll be trying to figure out how to send the data (i have the hardware sorted, its just the channel decoding and checksum that worry me)...so any ideas on that would really be appreciated too...

I'm using a PIC16f684, and programming with MPLAB and PICC Lite with a PICKIT2 programmer.

many thanks,

L
Laurie is offline  
Old 29th April 2008, 05:00 PM   (permalink)
Default

You just want a delay of 20us? Well if your clock frequency is 4Mhz, thats 1us per instruction, so just add 20 'nop' instructions ^^. That of course is the quick and dirty approach,. I assume you're using C here? what compiler? There are many generic delay routines that don't require any special functions.

Blueteeth

Edit: oops jsut noticed you're using PICclite. I've never used it, but surely a simple C delay like:

while (1)
{
for i=0; i<20; i++;
{
*do something whilst waiting?*
}


http://www.microchipc.com/sourcecode/#delay16x
__________________
Inconsistency is the key to flexibility!

Last edited by Blueteeth; 29th April 2008 at 05:07 PM.
Blueteeth is offline  
Old 29th April 2008, 05:10 PM   (permalink)
Default

yes i'm using C, with the PICC LITE compiler/assembler/linker toolsuite......this may be really basic, but how do i do NOP instructions?? quick and dirty is just fine, so long as it works ..

all i want to do is get the program to wait long enough for the ADC to accuratly sample each channel before saving the result and moving onto the next.....ps. i'm using the internal clock, currently set at 8Mhz...

is NOP a standard C instruction?/is there a standard NOP instruction in C??
Laurie is offline  
Old 29th April 2008, 05:28 PM   (permalink)
Default

Quote:
Originally Posted by Laurie
yes i'm using C, with the PICC LITE compiler/assembler/linker toolsuite......this may be really basic, but how do i do NOP instructions?? quick and dirty is just fine, so long as it works ..

all i want to do is get the program to wait long enough for the ADC to accuratly sample each channel before saving the result and moving onto the next.....ps. i'm using the internal clock, currently set at 8Mhz...

is NOP a standard C instruction?/is there a standard NOP instruction in C??
Often a C compiler will support an asm() function, and you would use it like this:
HTML Code:
void delay() {
  int i = 200;
  while (i--) {
    asm("nop");
  }
}
pc88 is offline  
Old 29th April 2008, 05:32 PM   (permalink)
Default

Oops, 'nop' is an assembly instruction, I was just spitting out idea's.

I would have thought your compiler allows one to insert assembly instructions (as assembly is so versitile). In which case look here:

http://www.phanderson.com/PIC/PICC/CCS_PCM/8591.html

This guy has a simple sasembly routine within a C program. Looks like he's using a 4Mhz osc, where 1 instruction = 1us. So this loop runs for 10 instructions. If you're using an 8Mhz osc, your PIC runs twice as fast, so this delay is only 5us. Therefore you'll need to call it 4 times for 20us.

// delay routines

void delay_5us(int t)
{
#asm
BCF STATUS, RP0
DELAY_10US_1:
CLRWDT
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ t, F
GOTO DELAY_5US_1
#endasm
}

for a 20us delay, with a 8Mhz osc: use 'delay_5us(4);'

Hope that helps, I use MikroC myself, which is a bit different but it seems a easier to use

Blueteeth
__________________
Inconsistency is the key to flexibility!
Blueteeth is offline  
Old 29th April 2008, 06:03 PM   (permalink)
Default

hmmm, it wont let me compile that either.....
going back to the quick and dirty method, would it work just to have a counter counting up to 40?

eg

int i = 0;

while (i<39)
{
i++;
}


or would another loop be more suitable?
or does it have to do something else at the same time?
or would this do the trick?
is this really bad programming practice?

or is there some obvious reason that PICC wont let me compile if i include the delay subroutines??

thanks again
Laurie is offline  
Old 30th April 2008, 02:02 AM   (permalink)
Default delay routine

Hi laurie, it's a lot simpler than you think to use the delay function. Please go to this site:
http://www.microchipc.com/sourcecode/#delay16x and download the delay routines ( might have to read the instruction) and copy the delay.h and delay.c into the same folder as your project. In your program, put #include "delay.h" and #include "delay.c"

Please refer my example program in Setting up ADC in P16F684(2).

I don't know why you couldn't access my program. May be you have to contact the Web master.

Good luck.
__________________
May the force be with you.


My project: Simple White Line Follower

http://au.youtube.com/watch?v=8Z_MmrdH4oc

http://i271.photobucket.com/albums/j...nefollower.jpg

Last edited by Wingmax; 30th April 2008 at 02:18 AM.
Wingmax is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
help with an interesting project magee Electronic Projects Design/Ideas/Reviews 10 19th August 2007 05:33 AM
Project for me, you. jat45 Electronic Projects Design/Ideas/Reviews 7 11th January 2007 04:04 PM
Project on Infrared technology..... achaizs Electronic Projects Design/Ideas/Reviews 20 2nd May 2006 08:16 AM
Need Assistance on Project pwollner Electronic Projects Design/Ideas/Reviews 17 19th February 2004 11:13 PM
I need a project idea based on my strength or interest. :) janetsmith2000@yahoo.com Electronic Projects Design/Ideas/Reviews 10 11th November 2003 10:33 AM



All times are GMT. The time now is 08:12 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

eXTReMe Tracker