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.

Pot Controlled Variable Timer in PIC12F675

Status
Not open for further replies.

thiru1879

Newbie level 6
Newbie level 6
Joined
Feb 5, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Visit site
Activity points
1,377
Hi, please tell me how to make variable timer using AN0 through potentiometer in PIC12F675 ?
 
Last edited by a moderator:

You create a timer interrupt of say 500 ms (minimum timer value) and use a variable as counter. You adjust a pot connected to ADC pin. This will give you a integer value which can be used directly or scaled and used for timer counter expiration value. If you need 1 sec timer then you adjust ADC such that counter is set to 2 and in ISR you check


Code C - [expand]
1
if(++count == adcVal) //do something



adcVal is set to 2 through ADC. When count becomes 2 timer does what it is programmed to do.
 

Hello!

I'm not a PIC user, but basically an if statement goes against the philosophy of using a
timer. The merit of a timer is precisely that you don't have to control its value, it handles
itself and wakes you up when overflowing.
So basically you have to find a way to set the value with PIC (create a function like this:
MyTimer.SetValue(adcval); Then if you also find a way to start the timer MyTimer.Start();
then the timer will call an interrupt routine when it reaches the previously set value.

NB: there are myriads of ways of using a timer. One shot, timely recurrent, etc... so what
I wrote might greatly vary (if it's recurrent, it will automatically call the ISR without having
to start it every time, etc...

Dora.
 

kindly check my code..,

i would like to pass the value of ADC into timer0 module but for testing, delay used here.


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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/********************************************************************
|              Tutorial 11C - PIC12F675 ADC Demo                    |
 ********************************************************************
 This program shows how to use the ADC (Analog-to-Digital converter)
 pin on a PIC12F675.                   
 This tutorial will work with the Hi-Tech C compilers.              
                                                                      
 iBoard connection as follows:                                        
    PIN             Module                                        
 -------------------------------------------                        
    GPIO0           LED1
    GPIO1           LED2
    GPIO2           LED3                        
        GPIO3           Switch (Reset)  
    GPIO4           10K Potentiometer       
 
**********************************************************************
|              [url]WWW.PICCIRCUIT.COM[/url]  (C) Copyright 2010                 |   
**********************************************************************
| This source code may only be used with PICCIRCUIT products only.   | 
| If you distribute the source code, the source code must have this  | 
| entire copyright and disclaimer notice. No other use, reproduction | 
| or distribution is permitted without written permission.           | 
**********************************************************************
|   Program: main.c                                                  |
|   Version: 1.0                                                     |
|-------------------------------------------------------------------*/
#define XTAL_FREQ   4MHZ        /* Crystal frequency in MHz */
#include <pic.h>
 
#define GPIO,05h
#define ontime GPIO0
#define offtim GPIO1
#define relay  GPIO2
#define led    GPIO4
 
 unsigned int ADC_Value=0,i,j,k,l,m;
void delay(unsigned int j);
// ============================================================
// Configuration Bits 
// ============================================================
__CONFIG(INTIO & WDTDIS & UNPROTECT & BORDIS & MCLREN);
 
/**************************************************************
                    Initialise System
**************************************************************/
void delay(unsigned int j)
{
for(j=0;j<6000;j++);
for(k=0;k<6000;k++);
for(l=0;l<6000;l++);
}
 
 
/**************************************************************
                    Main Program
/**************************************************************/
void main(void)
{
 
    TRISIO = 0b00000011;//Set GP0-GP1 as i/p GP2-GP5 as o/p
    ANSEL = 0b00110011;     //Frc, GPIO0(AN0)& GPIO1(AN1) Analog input
    
    CMCON = 0x07;   //Turn off analog comparator
    INTCON = 0x0B;
    
 
while(1)
{
ADCON0 = 0b10000000;    //Channel 03 (AN3), A/D converter ON
        GODONE = 1;         //Start Conversion
        while(GODONE){}     //Wait for conversion complete
        m=0.01*(ADRESH+(ADRESL<<8)); // 10 bit value converted into 0-10 scale
relay=1;
 
delay(m);
delay(m);
delay(m);
 
relay=0;
 
delay(m);
delay(m);
delay(m);
delay(m);
 
}
}

 

If you use delays then your MCU will not be able to do any other thing when it is executing delay. Use Timer Interrupt and ADC to create required delay which can be preset by a preset. First note down the min and max delays you will be needing and do the calculations.
 

I would like to set the total range of timer is 0-10mts, this variable time value to be received from ADC and which value to pass into Timer module, this my idea.

kindly guide me ,how to pass the value of ADC ie "m" mentioned in my code into timer module in PIC12F675?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top