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

Measurement of pulsewidth at 10 ports

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



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

Measurement of pulsewidth at 10 ports
PostPosted: Thu Aug 30, 2007 3:22 am     Reply with quote

I need to measure the pulsewith at 10 ports. I can do it for every single pin, but is there a better method to do it with a for()?
Example: while ( !input(EINGANG_i_1) ) (I know this won´t work, but you see what i mean...)

Here is the code for the single pin measurement:
Code:


#define   EINGANG_1_1      PIN_A4
#define   EINGANG_2_1      PIN_A5

#define   EINGANG_1_2      PIN_F2
#define   EINGANG_2_2      PIN_F3
#define   EINGANG_3_2      PIN_F4
#define   EINGANG_4_2      PIN_F5

#define   EINGANG_1_3      PIN_E0
#define   EINGANG_2_3      PIN_E1
#define   EINGANG_3_3      PIN_E2
#define   EINGANG_4_3      PIN_E3

long   IMPULSBREITE_[10];

void Komplettmessung (void)
   {
   long   WERT_[2];

//PIN 1 /////////////////////////////////////////////////////////////////////////////
   WERT_[1] = 1;
   WERT_[2] = 0;

   while ( WERT_[1] != WERT_[2] )
      {
      for (t=0; t<2; ++t)
         {
         while ( !input(EINGANG_1_1) )
            {
            NOP;
            }
         SET_TIMER1(0);
         while ( input(EINGANG_1_1) )
            {
            NOP;
            }
         WERT_[t] = GET_TIMER1
         }
      }
   IMPULSBREITE_[1] = WERT_[1];

//PIN 2 /////////////////////////////////////////////////////////////////////////////
   WERT_[1] = 1;
   WERT_[2] = 0;

   while ( WERT_[1] != WERT_[2] )
      {
      for (t=0; t<2; ++t)
         {
         while ( !input(EINGANG_2_1) )
            {
            NOP;
            }
         SET_TIMER1(0);
         while ( input(EINGANG_2_1) )
            {
            NOP;
            }
         WERT_[t] = GET_TIMER1
         }
      }
   IMPULSBREITE_[2] = WERT_[1];

to be continued.....
   
   
   }
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Aug 31, 2007 9:55 am     Reply with quote

Any ideas? I´m sure CCS has a solution...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 31, 2007 10:33 am     Reply with quote

If you ask a design question like this, you need to give us information
on the input signals and other issues:

What is the frequency of the input signals ?
Are they synchronous ? If so, on what edge ?
What is the expected range of the duty cycle ?
What accuracy is required in the pulse width determination ?
What PIC are you using ?
What is the oscillator frequency of the PIC ?
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Fri Aug 31, 2007 11:48 am     Reply with quote

Look in the devices directory for your pic's .h file. In it they define all the PIN_A0, PIN_A1, ... names as numbers. It won't be understandable code, but you can use those numbers, either in a FOR loop if all pins happen to be sequential, or call a single routine with the pin number as parameter.
Guest








PostPosted: Mon Sep 03, 2007 1:24 am     Reply with quote

Hi,

frequency: 50Hz
Synchron: no
duty cycle: 16ms low, 500ms - 2500ms high
acuracy: max. at 16MHz 0,25µs - a little offset doesn´t matter
Pic 18F452
Osc.: 16MHz


@mskala: I found the numbers in the .h file. Can I renumber them from 0- .... ?
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Mon Sep 03, 2007 1:26 am     Reply with quote

Hi,

frequency: 50Hz
Synchron: no
duty cycle: 16ms low, 500µs - 2500µs high
acuracy: max. at 16MHz 0,25µs - a little offset doesn´t matter
Pic 18F452
Osc.: 16MHz


@mskala: I found the numbers in the .h file. Can I renumber them from 0- .... ?

Sorry for double post - wrong pulsetime. They are from a receiver
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Tue Sep 04, 2007 2:34 am     Reply with quote

Thanks for the Tip with the numbers, it would work. But how can I change this numbers that they are all in a row?

For Exampe I want PIN_A0, PIN_A1, PIN_B3, PIN_B4, PIN_C5 and so on in a row:
Code:
#define PIN_A0  31744
#define PIN_A1  31745
#define PIN_A2  31746
#define PIN_A3  31747
#define PIN_A4  31748
#define PIN_A5  31749
#define PIN_A6  31750
#define PIN_A7  31751

#define PIN_B0  31752
#define PIN_B1  31753
#define PIN_B2  31754
#define PIN_B3  31755
#define PIN_B4  31756
#define PIN_B5  31757
#define PIN_B6  31758
#define PIN_B7  31759

#define PIN_C0  31760
#define PIN_C1  31761
#define PIN_C2  31762
#define PIN_C3  31763
#define PIN_C4  31764
#define PIN_C5  31765
#define PIN_C6  31766
#define PIN_C7  31767


better would be for me:
Code:
#define PIN_A0  32000
#define PIN_A1  32001//canged
#define PIN_A2  31746
#define PIN_A3  31747
#define PIN_A4  31748
#define PIN_A5  31749
#define PIN_A6  31750
#define PIN_A7  31751

#define PIN_B0  32002//canged
#define PIN_B1  32003//canged
#define PIN_B2  31754
#define PIN_B3  31755
#define PIN_B4  31756
#define PIN_B5  31757
#define PIN_B6  31758
#define PIN_B7  31759

#define PIN_C0  31760
#define PIN_C1  31761
#define PIN_C2  31762
#define PIN_C3  31763
#define PIN_C4  31764
#define PIN_C5  32004//canged
#define PIN_C6  31766
#define PIN_C7  31767


is this possible? I tried to simulate but it don´t work. Where do this numbers come from-where are the defined?
Ttelmah
Guest







PostPosted: Tue Sep 04, 2007 2:46 am     Reply with quote

The numbers, are the memory address where the port is mapped, and the bit number _in_ this address, coded as address*8+bit_number.
These are set by the hardware of the chip. You cannot change them.
However consider a look_up table.
Code:

int16 port_to_use[] = {
   PIN_A0, PIN_A1, PIN_B3, PIN_B4, PIN_C5
};

Obviously with all the entries you want, in the order you want them.
Then to access the first port, just use:

output_high(port_to_use[0]);

Using a variable like this, will only work with the V4 compiler. However coe has been posted here in the past by a number of people (myself included), to give this behaviour with the old compiler.

Best Wishes
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Tue Sep 04, 2007 4:49 am     Reply with quote

Perfect!! Thanks a lot...
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