Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Using PIC10F200 and TMR0 to create a 5 minute timer

Status
Not open for further replies.

fmicro

Newbie level 3
Joined
Jul 1, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
USA
Activity points
1,313
pic10f200

Hi,
I have recently written some basic code with the PIC10F200 and am now trying to incorporate a 30 minute timer.

Currently here is my best understanding of how I can do this. I am fully expecting to be incorrect in some of my assumptions but here goes:

1. Set a large prescaler for the Timer0 Rate of 1:128 (I suppose I could even use 1:256)
2. Test bit 7 of Timer0 noting when it changes from low to high meaning it has transitioned from 0x7F and assuming 0x7F*128 cycles = 16.25mS.
3. Determine how many occurrances (or multiples) I need to reach my desired time.


That's it. From here I plan to disable my outputs and some other simple stuff until there is a transition on the input pin (I think I know how to do this part)

To start off with, can anyone help me with the proper way to write these commands? Does the following look like I am on the right track and is the syntactax correct?


; Here I just want to access and initialize Timer0
CLRF TMR0 ; clear
MOVLW '00xx0110'b
OPTION ; set PSA to Timer0 and rate to 1:128

; Here I just want to test bit 7 of TMR0
CHECK
BTFSS TMR0,7 ; test if bit 7 is set
GOTO CHECK ; if not set then keep checking
; if it is set, I increment a counter etc.


I mostly wnat to make sure the syntax is correct and a little bit of advice will get me going for a while.
Your comments will be appreciated.

Thanks,
fmicro
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
pic10f200 example code

Hi Fmicro,

Writing Pic code is about having fun and experimenting - don't be afraid of the code and Mplab - use its powerful and helpful features to check your work.

You check your syntax by Building the code, Assembler then gives you a reports showing if it was 100% correct or a list of what errors it detected.

Your code looks find to me, but is only partially complete - when using TMR0 as a timer you must ensure the Watchdog function is switched off.

You can see from the pdf / screen shot that you can write the Config bits in to your code or do it via the Configure Bits Window in MPlab.

On that screen shot, I'm using the MPLAB debug SIM function, it basically runs your code as if it was in a pic10F200 chip, a Watch window was created to let you see the TMR0 incrementing with each cycle - to see it working press F7 - single step - you also see the cursor moving along your code as it executes each instruction.

hth

Also in SIM is another feature - STOPWATCH - this allows you to accurately time a function , so in your code, you can time how long it takes TMR0 to get from 00 - 80h

Using TMR0 to create your time Delay is one way, and while TMR0 is counting down the core is free to do other work, on larger chips that have interrupts you do not need to keep constantly testing to see if its done - the interrupt will tell you instead.

Another way to create your Time Delay is the classic Delay routine, there are loads of tutorials for this, the downside of them is that the core is dedicated to the delay loop so nothing else can run while that is executing, but it is very usefull for small delays of the odd msec.
 

fmicro

Newbie level 3
Joined
Jul 1, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
USA
Activity points
1,313
pic10f200 code

Thank you for your reply and helpful hints.

Interesting that you mentioned I can use a simple delay routine. That might even be the way for me to go. I simply have a situation where various outputs are toggled high and low, but if any one output is high for 5 minutes or more (maybe even 30 minutes - I would adjust this to what I want), I would set all outputs low because this would indicate a condition where a user left the device on unintentionally and so this timer is just a fail safe routine.

I was originally thinking of using the WDT and SLEEP mode, but it is my understanding that this is not the correct approach with the 10F200 devices because the WDT is only good for timers of milliseconds or so. Do you know if this is correct?

I presently have a simple looping delay routine in the code in order to handle debounce occurring when the switch is pressed. Were you suggesting that I can just add another looping delay routine that runs for several minutes of my choice?

I am open to other timer solutions with the 10F200 as well.

Thanks much!
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
pic10f200 timer

Hi,

The function of the Watchdog is to reset the micro to the beginning of the program if its timer is not regularly restarted - so would not think its a good choice for a timer.

A typical timer /clock system would be to create a delay of 1sec and then count up like a rtc - but this would normally be done by the interupt system so you can carry on with other things while the TMRs are running.

On your little chip your choices are so limited, it hard to advise the best thing as I don't know what you are trying to achieve, you mention turning on two outputs and a switch input with debounce.

Your debounce will probably be around 50ms - you can have a main delay loop of 1sec , but within that loop add in a btfss to see if the switch has been pressed, if so it would then service that action, but this would then add about 100ms extra to that 1 sec delay - but I doubt that would be a problem for you whole routine.
Similarly the control of your output ports can be done at the same time or upon the change of a seconds or minutes counter, this only needs a few instructions which again only take the odd ms and will make little difference to you timing loop.

See this link for a handy delay code calculator
http://www.piclist.com/cgi-bin/delay.exe
 

fmicro

Newbie level 3
Joined
Jul 1, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
USA
Activity points
1,313
pic10f200 sleep

Excellent advice.
Thank you very much.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top