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

How to set the pulse width of less than 500us of the 12f617

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



Joined: 23 Oct 2006
Posts: 12

View user's profile Send private message

How to set the pulse width of less than 500us of the 12f617
PostPosted: Mon Jan 22, 2018 6:32 am     Reply with quote

There is a problem in my program.
If external oscillator 32768 is used, I can't get a pulse less than 500us.
I set pulse width to be 250us, but the output pulse width is 500us. No matter how I modify the pulse width which is less than 500us´╝îoutput is always 500us.

If the internal 4M crystal oscillator is used, the output pulse is normal. That is to say, the set is 250us then the output is also 250us.

Why is this? I need a 250us pulse, but I can't know how to setup this code. How to solve this problem, I want to output a 250us pulse.


Thank you!
The version is 5.015

Code:

#include <12F617.H>

#fuses LP, NOWDT,NOPROTECT,BROWNOUT, NOPUT,NOMCLR// INTRC_IO
#use delay(clock = 32768, xtal) //minum delay 500us

//#fuses INTRC_IO, NOWDT?NOMCLR, NOPUT, NOPROTECT
//#use delay(internal=4000000)

while(TRUE)
   {
output_high(PIN_A1);
        delay_us(250);  //pulse width =250us     
   
     output_low(PIN_A1);  //600ppm delay=100ms, 400ppm delay=150ms
 
// 240ppm
       delay_ms(250); //240ppm delay=250ms


    }
Ttelmah



Joined: 11 Mar 2010
Posts: 13269

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 7:00 am     Reply with quote

The fastest you can get 244uSec, by selecting fast_io, and no delay.

At 32768Hz, each instruction of the chip itself takes 122uSec.
A pulse implies turning on, then off, so two instructions. 244uSec.

You were seeing 4 instructions, since using standard_io (the default), has the processor controlling the TRIS for every I/O operation. So 488uSec minimum.


Code:

#include <12F617.H>

#fuses LP, NOWDT,NOPROTECT,BROWNOUT, NOPUT,NOMCLR// INTRC_IO
#use delay(clock = 32768, xtal) //minum delay 500us

#use fast_io(a)

//Now inside the main, _you_ will need to control the TRIS
   output_drive(PIN_A1); //set A1 as an output

   while(TRUE)
   {
        output_low(PIN_A1); 
        output_high(PIN_A1);
   }
longmenok



Joined: 23 Oct 2006
Posts: 12

View user's profile Send private message

PostPosted: Tue Jan 23, 2018 11:45 pm     Reply with quote

Thank you very much! Ttelmah.
It can work normally.
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