News:

;) This forum is the property of Proton software developers

Main Menu

Using the internal 31.25khz osc

Started by RGV250, Oct 14, 2022, 11:30 PM

Previous topic - Next topic

RGV250

Hi,
I have a project where I need to save power, I am not sure how much yet. I do not want to mess about with sleep etc unless I have to so running it slow with this internal osc should suffice. The code is quite simple and does not use any special commands apart from delays where timing is involved.
I know that I cannot declare this xtal speed but if I set the correct registers up to select 31.25khz int osc and tell the program xtal = 4mhz is there anything stopping me. If I have my sums right a "DelayuS 1" would actually be 128uS so all I need to do is adjust accordingly.

Regards,
Bob

John Drew


ken_k

I think my mind is running on a slow clock these days.

shantanu@india

Check watchdog timing if you have it enabled.
Regards
Shantanu

top204

Depending on the device used, make sure you have the config fuse setting enabled for software oscillator switchover.

Then create a procedure to set the clock to its lowest frequency, then to its normal frequency, if required.

Or if the KHz clock is always going to be used, just set it up in the config fuses.

RGV250

Thanks, I rarely use the watchdog but a very good point to remember if I do.

I think it will be permanently on the khz setting, it is basically an infra red sensor and a motor that gets pulsed on/off a couple of times a day.

I got bought one of those bins which you wave your hand in front and it opens, it matches the new kitchen and I do not want to upset the person that bought it for me but it is annoying as no sooner have you got your hand in the bin the flap closes. There is a load of space in the lid so I figured a PIC will allow me to do a better job than the designer who has probably never used a bin.

Bob

top204

As mentioned above, you can just place the microcontroller to sleep and wake it up when the IR sensor detects a signal. Use one of the INT pins to wake the microcontoller up when it receives a High to Low or Low to High signal, then put it back to sleep when finsihed moving the motor, with the Sleep command without a parameter follwong it.


RGV250

Hi,
I need to flash an LED every so often so it looks like it would be easier (and probably better on battery) to use snooze and sleep rather than the low int osc.

Bob

trastikata

Quote from: RGV250 on Oct 15, 2022, 12:07 PMI got bought one of those bins which you wave your hand in front and it opens...

My guess is you want to connect the output of the sensor to the PIC and the MCU will control the lid opening mechanism?

Then you can connect the sensor output to one of the HW interrupts and use a deep sleep. The HW pin interrupt can wake the device from deep sleep and run it at 4 MHz for few seconds while monitoring the sensor to see if your hand is still there. Then put it back in sleep.

No need switching to KHz oscillator since the power drawn running occasionally the MCU at 4MHz for several seconds is fraction of the power consumed by the opening mechanism.

top204

#9
I did this type of mechanism in a project.

1. Enable the watchdog in the fuses, and set its window for the time required to wake up and flash an LED every xx seconds. This is only possible on some of the newer devices. By newer, I mean post 2011. :-)

2. Setup an INT pin to wake the device when a signal appears on it.

3. As soon as the device wakes up, clear the watchdog timer and do the things required. i.e. Check if it was an INT that woke it up, and if it was, decode the IR signal and operate the motor. If it wasn't, just flash the LED with a fast on period.

4. Clear the watchdog timer, then place the device back to sleep with the Sleep command on its own, and wait for the next wake event.

This means the device is asleep for most of the time, so the current drawn is in the microamps, even if the device is operating at 64MHz when awake, as long as pins that are not used are set low and peripherals that are not required are disabled when in sleep mode. All of this can be done in one Do-Loop, that calls procedures or subroutines to do things when required.

The only device that may draw current all the time is the IR sensor, so choose one that has a low current if using a decoder type. Also, use the HLV peripheral inside the device to check if the batteries are coming to their end, and rapidly flash the LED when it wakes up, instead of a single flash, so it can be seen that the batteries need changing.

With the above mechanism, you can easily get years of life out of the batteries, as long as the motor is not driven too often. :-)