Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

sleep and 12C508A

Status
Not open for further replies.

SnM

New Member
I wrote and burned a program using sleep and wdt for a delay into a 16F84A, and it worked as expected. Simulated it a lot with MPLAB IDE v6.40.

I am trying to write a program for the 12C508A that also uses sleep and wdt as a delay, but as I am trying to simulate it, it does't work as expected.

When the wdt goes to zero, and it wakes the pic up from sleep, it does a full reset, instead of just moving on to the next instruction like how it worked on the 16F84A. am i overlooking something?

This is what I am loading that into my option reg.

11001001

:quick reference to what each bit of the option reg means:

bit 7: GPWU: Enable wake-up on pin change (GP0, GP1, GP3)
1 = Disabled
0 = Enabled

bit 6: GPPU: Enable weak pull-ups (GP0, GP1, GP3)
1 = Disabled
0 = Enabled

bit 5: T0CS: Timer0 clock source select bit
1 = Transition on T0CKI pin
0 = Transition on internal instruction cycle clock, Fosc/4

bit 4: T0SE: Timer0 source edge select bit
1 = Increment on high to low transition on the T0CKI pin
0 = Increment on low to high transition on the T0CKI pin

bit 3: PSA: Prescaler assignment bit
1 = Prescaler assigned to the WDT
0 = Prescaler assigned to Timer0

bit 2-0: PS2:pS0: Prescaler rate select bits


Thanks, Steve
 
SnM said:
When the wdt goes to zero, and it wakes the pic up from sleep, it does a full reset, instead of just moving on to the next instruction like how it worked on the 16F84A. am i overlooking something?

When the WDT times out the chip is supposed to do a full reset, your program needs to check a status flag to see if it was a normal reset or a WDT reset and take the appropriate action. From what I remember, details are in the datasheet.
 
so how would I go about resuming my program after using sleep on the 12c508a? Why does the 16f84A work differently?
 
SnM said:
so how would I go about resuming my program after using sleep on the 12c508a? Why does the 16f84A work differently?

Page 38 and 39 of the 12C5xx datasheet tell you about reset conditions, there are SIX different types of reset available - you need to check the status bits (listed on page 39) to find out if the WDT caused the reset from sleep.

Presumably your program is going to sleep at a particular point, all you need to do is, from reset, check if it was caused by a WDT timeout during sleep, and jump to where you want the program to resume from. The datasheet also discusses which registers are changed or not for the various reset conditions.

Certainly the 16F84A is simpler to use (for your application), but is probably less versatile.[/code]
 
yeah, the 16F84A was much easier to use. I have a program running, and when the wdt wakes it up from sleep, it just continues like normal.

I did modify my program for the 12c508A to copy the PCL into a registry before going into sleep mode, and then after the reset on wakeup, i checked the 3 bits in that status to see if the wdt caused the wake up. if so, I added "2" to the PCL number I have saved, and then moved that to the PCL, and that took me right were I wanted to go.

but.......I noticed that my config registry was being effected some how, and changed my prescaler to 1:128, when I originally had it set to 1:2. I noticed other things were being reset too, but I forget what they are now.

I found it too much of a hassle, so I figured I would forget it. I was trying to use it to debounce the inputs for 36 ms. an added bonus was my circuit would use less power too. oh well, I just decided to use a subroutine that delays for 20ms.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top