Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

5micro sec delay using pic12f675 ...not working

Status
Not open for further replies.

Teja.p

Member level 2
Member level 2
Joined
May 29, 2016
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,728
here is my code please help meee
i am using pic12f675 with20Mhz clock and
i want to generate 5us delay ..
i calculate by using formula
Pic input frequency= Fosc / 4= 20 Mhz / 4 = 5 Mhz
Prescaler = 1:4
Tick Counter frequency = Prescaler/5 Mhz = 4 / 5 Mhz = 0.8 u s
Delay required =5us
Delay required = Timer Count * Tick Counter frequency
by using this formula timer count is 249

please help mee ..




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define IP  GP0_bit
   #define OP1  GP1_bit
   #define OP2  GP2_bit
     void delay();
    void main()
{
unsigned int count=0;
     /*GPIO=0X00;
     TRISIO=0X00;
    /// WPU=0x00;
 
   ANSEL = 0;
   CMCON = 7;    */
   ANSEL  = 0x00;       // Set ports as digital I/O, not analog input
        ADCON0 = 0x00;                 // Shut off the A/D Converter
        CMCON  = 0x07;                 // Shut off the Comparator
        VRCON  = 0x00;             // Shut off the Voltage Reference
        TRISIO=0X01;///GP0 and GP1 are the inputs and GP2 and GP4is the output
        GPIO   = 0x00;       // Make all pins 0
        OPTION_REG=0X41;
        TMR0=0X00;
    while(1)
    {
    OP1=1;
    delay();
    OP1=0;
    delay();
}
}
  void delay()
     {
         TMR0=249;
        T0IF_bit = 0;                                // Clear interrupt bit
        T0IE_bit= 1;                                // Enable Timer1 interrupt
        PEIE_bit= 1;                                 // Enable peripheral interrupts
        GIE_bit= 1;                                // Enable global interrupt
        
        if(T0IF_bit==1)  //If Timer1 Interrupt
        {
                T0IF_bit= 0;    // clear the interrupt
        }
     }

 
Last edited by a moderator:

Hi,

There is no error description in your post.
There is no question in your post.

Tick Counter frequency = Prescaler/5 Mhz = 4 / 5 Mhz = 0.8 u s
This is no frequency. It is a period time. Frequency is 1.25MHz

Delay required = Timer Count * Tick Counter frequency
by using this formula timer count is 249
..according your data:
5us = timer_count x 0.8us --> timer_count = 5us / 0.8 us = 6.25
Using true frequency makes no sense, because the unit of the result then is s^2...

Klaus
 

thank u for replay sir..


i am using pic12f675 with 20MHz clock
i want to generate 5us delay..
how to calculate the TMR0 VALUE..

I use this formula for calculate the TMR0 VALUE...
Pic input frequency= Fosc / 4= 20 Mhz / 4 = 5 Mhz
Prescaler = 1:4
Tick Counter frequency = Prescaler/5 Mhz = 4 / 5 Mhz = 0.8 u s
Delay required =5us
Delay required = Timer Count * Tick Counter frequency
by using this formula timer count is 249

BUT 5micro sec delay is not generating ...

please help mee sir..
 

Regardless of the calculation, if each instruction takes 0.2uS (assuming single cycle instructions) the chances of a function call, loading a timer and checking the interrupt flag then returning in less than 25 clock cycles is fairly remote.

A better solution would be a block of assembly code instructions to kill time, perhaps a "decfsz" to a variable repeated in a short loop. It would be more accurate , more consistent and use far fewer instructions.

Brian.
 

thank u for u r suggestion sir..

but my requirement is to generate pwm with 50us on period and 50us off period..
how to calculate the TMR0 value for generate the 5 or 50us delay for PIC12F675..
I study on internet but it was not working..
please help mee sir..
 

Hi,

This is a different task.

I recommend to use a microcontroller with PWM periferal.
Then read the datasheet on how to generate a 10kHz PWM with 50% duty cycle.

*****
"It was not working" is meaningless.
* write what you expect
* write how you tried to achieve it
* write what you see (description, timing, levels, scope picture...)
* try to debug the problem
* write your debugging results

Klaus

- - - Updated - - -

Added:

You are free to do simple internet search "pic pwm calculator" or "pic12f675 pwm" on your own.

Klaus
 

hello,


you are not using Timer0 interruption ..


so only pool the timer0 overflow bit ...
and avoid to call a subroutine wich need to grab some cycles ..

Code:
      while(1)
    {
    OP1=1;
         TMR0=232;                // 256-230=25  25*0.2=5µS @ 20MHz
         T0IF_bit = 0;               // Clear iFlag Timer0
         while (T0IF_bit==0)  //wait to timer0 overflow
    OP1=0;
        TMR0=232;  // 256-232=24  a bit less than  24*0.2=4.8µS @ 20MHz
        T0IF_bit = 0;               // Clear iFlag Timer0    + 0,2µS
        while (T0IF_bit==0)  //wait to timer0 overflow       + nay cycles
     }
     }

you can adjust the value 230 .. 234 ..to compensate the timing error
 
Last edited:

Tick Counter frequency = Prescaler/5 Mhz = 4 / 5 Mhz = 0.8 u s
Delay required =5us; Delay required = Timer Count * Tick Counter frequency
by using this formula timer count is 249


How? Can you give more details?

- - - Updated - - -

Tick Counter frequency = Prescaler/5 Mhz = 4 / 5 Mhz = 0.8 u s
Delay required =5us; Delay required = Timer Count * Tick Counter frequency
by using this formula timer count is 249


How? Can you give more details?

Sorry, I did not see the other posts. You cannot use the raw clock cycle, you can only use the clock after the pre scalar. The microcontroller works in chunks of prescalar cycles.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top