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 CCS Technical Support

pyd 1998 12f675

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sabobey



Joined: 19 Oct 2008
Posts: 6

View user's profile Send private message

pyd 1998 12f675
PostPosted: Tue Jul 31, 2012 4:07 am     Reply with quote

#include <12F675.h>
#use delay (clock=4000000)
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOMCLR
#define sens PIN_A1


int8 i,j;
int16 data=0,dat;


void main() {
SET_TRIS_A (0b00001111);
while(true)
{


data=0;
input(sens);

while(input(sens)){
delay_cycles(60);

for (i=0; i < 15; i++){

output_low(sens);
delay_cycles(25);
output_low(sens);
delay_cycles(25);
output_high(sens);

input(sens);
Data <<=1;

}
output_low(sens);
delay_cycles(200);
input(sens);
delay_cycles(200);
dat=data;
}
}
}

pyd 1998
how to get into data
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 31, 2012 8:01 am     Reply with quote

Hi sabobey,

It's clear that you don't "get it" on a whole bunch of levels. Here is what I mean:

1. This is now the THIRD thread that is going on the 12F675/PYD1998. Don't do that, use the original thread to get help on this subject.

2. You didn't use the 'Code' tags when posting your code, so the formatting was not preserved. This makes the code very hard to read.

3. You simply dumped a bunch of code on us without telling us what works, and what doesn't work. The majority of us will not have a PYD1998 to test, so any extra troubleshooting information you can give us will be very important!!

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Jul 31, 2012 8:53 am     Reply with quote

I think the other threads have been locked, which is why he is trying again.

At least an attempt at the code. Smile

As EzFlyr says - _learn to use the code buttons_.
Code:

#include <12F675.h>
#use delay (clock=4000000)
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOMCLR
#define sens PIN_A1

int16 read_sensor(void) {
   int n;
   int16 data=0; //ensure value starts clear
   delay_us(25); //must delay 25uSec after the pin goes high
   for (n=0;n<15;n++) {
      output_low(sens);
      delay_cycles(1); //at 4MHz this is 1uSec - plenty
      output_high(sens);
      output_float(sens); //sets the pin 'undriven'
      data<<=1;
      delay_us(3); //may need tweaking
      if (input(sens))
         bit_set(data,0); //quicker than addition on the PIC for this
   }
   output_low(sens);
   delay_cycles(1);
   output_float(sens);
   return(data);
}

void main(void) {
   signed int16 val;
   
   do {
        if (input(sens)) {
           val=read_sensor();
           //now you have to do 'something' with the number
        }
   } while (TRUE);
}


You don't need to set tris, the compiler does this for you when you read/write the port.

This should return the raw 'number'. However you will need to have an initial 'setup' phase, where you cover the sensor, and take a reading, then subtract this value from the incoming readings to get the 'delta'. You might need to consider using a 'signed' value for doing this - why I put the result into a signed....

What you now 'do' with this number depends on what you are actually after.

The only thing that may need 'tweaking' is the delay after the pin is set to float. They use 5uSec total in the example. However the 16bit rotation will already have taken a few uSec at 4MHz, so I have cut it to 3uSec. They say to experiment....

Best Wishes
sabobey



Joined: 19 Oct 2008
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 31, 2012 12:37 pm     Reply with quote

Hi ezflyr
Thank you.
I will take into account your suggestion.



Hi Ttelmah thank you for your help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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