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

INT RB0 or CCP in capture mode

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



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

INT RB0 or CCP in capture mode
PostPosted: Thu Feb 10, 2011 8:03 am     Reply with quote

Hello Guys!

I'm working on a project, and I'm in trouble what to use.
I have to measure the incoming signal frequency (square wave), and depending on it, I have to add a calculated delay, and then activate an output. I have to add this delay immediately after the signal, and must not to lose any of the signals...also I have to send the frequency value to rs232 once or twice per second. The frequency range is 50..300Hz.

I don't know what to do... capture the signal on RB0 and then in the isr make the delay, or measure with CCP, and then in the main.

Or make it without interrupt handler just in the main?

Thanks a lot!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 10, 2011 1:40 pm     Reply with quote

Tell us what the project is about. Tell us what device is giving these
signals to the PIC. Tell us what device the PIC must control.
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 21, 2011 3:54 pm     Reply with quote

I want to make a cdi ignition, with programmable advance for my scooter...
Yes, I know that there are some on the internet yet, but I want to build my own, I also need it for graduate work in the school.

So the signal comes from an inductive pickup - 2-3V sinus signal, and pic must control a thyristor.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 3:05 pm     Reply with quote

I have not done this type of project. But I think you need to make an
external circuit that cleans up the incoming waveform. Maybe use an RC
low-pass filter to remove noise. Then run it through a Schmitt Trigger
level converter chip, to change the logic levels to 5v CMOS levels.
I'm assuming the signal doesn't go below ground. If it does, you will
need additional circuits.

Then you can run the signal into the External Interrupt pin on the PIC.
Then inside the #int_ext routine, you could enable a hardware timer, such
as Timer0. This would set the delay time. Also enable the Timer0
interrupt. Then, when the Timer0 interrupt occurs, you can set your
"advance" signal to a high level. Then set Timer0 again, to control
the duration of the "advance" signal.

These are just some rough ideas.


For the frequency of the incoming waveform, you can also connect the
signal to the CCP input on your PIC and use the tachometer code which
can be found on this forum (use the search page).
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Sun Mar 20, 2011 7:25 pm     Reply with quote

Thank you PCMProgrammer!
I made it, and it works!

Now I have another problem. I want to send an int16 array[40] on the uart from the PC to the pic, and I dont know how to transfer it.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 1:31 pm     Reply with quote

What device are you sending the data to ? What format does this device
need for the data ? ASCII bytes ? or binary bytes ? Does it need the
data to be a packet, with a specific protocol for the packet ?
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 22, 2011 1:48 pm     Reply with quote

The device is 16F628a. I want to transfer a lookup table for the pic. I need to store it in the program memory, because the data memory is out of space. The pic is connected with the hardware usart to the PC with a USB-TTL converter...
I read in the manual that I need to use write_program_eeprom() function, but did not found example for it.
Also did not found example to transfer the array.

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 2:57 pm     Reply with quote

I'd be looking at trimming your code to gain the 80 or so bytes you need for the lookup table.
That PIC has 2KB of program space, should be lots for a CDI system with RS232 communications.It's really 'tons of space' to guys like me who only had 8KB for entire remote SCAD systems that did a heckuva lot more work !
Next bet, upgrade the PIC to say a 16F648a....
But I'm sure you can trim the fat and get it all under the hood !
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 22, 2011 4:25 pm     Reply with quote

Yes, you are right.
But I need 2 of the lookup tables, thats about 160bytes of data, too many for the data memory. The program memory has a lot of free space, and thats why i want to store there the data, just dont know how to do that:)
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Sun Mar 27, 2011 4:06 pm     Reply with quote

I tried to transfer the lookup table from the PC to the pic. It is an int16 array[28] with numbers from 0-35000. I send every value with \r at the end...But it receive only 3 values correct, the other are incorrect...if i only printf the values, then all the values are correct... I think the problem is the size of the serial buffer... it takes too much time to convert the values.
How can i solve this? make a delay between sending values? or make some handshake routine?
And the other question, will it store the data permanent like this way, or delete after power down?

Thanks
Code:

#include <stdlib.h>
#fuses NOMCLR,NOLVP,HS,NOWDT,NOPUT,NOBROWNOUT
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,STREAM=COM)

int16 delay[28];

**********
void main()
{

if(!input(PROG)){

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

    fgets(buff,COM);
    delay[i]=atoi(buff);
    //printf("%s",buff);
  }
  for(i=0;i<28;i++){
    printf("%lu ",delay[i]);
  }
}
}
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 27, 2011 6:08 pm     Reply with quote

First, you need to add 'errors' to the options in the use rs232(..) line...

Second, you're saving that data to RAM so power off ..there's goes the data..

You can 'hard code' the tables into program memory, which will eliminate the two problems.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Mar 28, 2011 1:47 am     Reply with quote

If you declare a value as 'const', it is stored in program memory.
So:
Code:

const int16 look_up[] = {1,2,3,4,5,6,7,8,9,.......};


Stores the 16bit array 'look_up', in the program memory.
Limitations:

You can't use _pointers_ to an array declared this way.
There is an overhead of about 20bytes, to add the retrieval code for this.
Obviously, you can't write to it. It has to be pre-declared at compile time.

Best Wishes
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 28, 2011 5:35 am     Reply with quote

I solved my problem with the incorrect values. I had to use atol() instead of atoi(), because it is for 8bit numbers...

Thanks for the const array, but how can i store a lookup table during runtime? I want to transfer it from my PC, not declared at compile.

Thanks!
CheeseE



Joined: 10 Feb 2011
Posts: 8
Location: Hungary

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 28, 2011 4:11 pm     Reply with quote

Every day i have another question:)
Today question is: How can I speed up the calculation of this expression:

Code:
delayus=time/360*delay[a];


where delayus is int16, time is int16, and delay[] is int. Now it takes about 150us @ 16Mhz
Thanks
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