interesting RF project needs a little assistance :)

Status
Not open for further replies.

Laurie

New Member
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
 
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?*
}


https://www.microchipc.com/sourcecode/#delay16x
 
Last edited:
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:
void delay() {
  int i = 200;
  while (i--) {
    asm("nop");
  }
}
 
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:

https://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
 
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
 
delay routine

Hi laurie, it's a lot simpler than you think to use the delay function. Please go to this site:
https://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.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…