Need a fast way to switch to 31khz low power oscillator

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Need a fast way to switch to 31khz low power oscillator

Post by Kenrix2 »

I am experimenting with some very low current power supplies and i need a way to switch to the low power internal 31khz oscillator as quickly as possible. The default internal oscillator on startup is 500khz which way exceeds the current available. Adding a c code icon in flowcode and setting osccon to zero at the beginning doesn't seem to work, I think it takes to many clock cycles to get to that point.

What I am looking for is to have the very 1st instruction (preferably @ org 0x00000000) to clear the osccon register and then goto _startup. Or, at least, have the very 1st instruction in _startup to clear the osccon register. Clearing the osccon register sets the clock to 31khz low power. I am do the experiments using using the PIC16LF1824 and the PIC16F1824. If you want to try it, you could series 2 slightly drained AA or AAA batteries and then feed it thru a 100k resistor to power the micro.


Everything I have tried so far in supplemental will not compile. Any ideas or suggestions?

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Need a fast way to switch to 31khz low power oscillator

Post by kersing »

To add this to the start of the generated main code:
Open 16f1824.fcd (in Flowcode4\FCD folder), find the line with "Initialise", add you C code just after the opening quotes. (Backup the file before writing the modified one)

All flowcharts for this chip will now start with this code, this means you will need to remove it if you want to write code for these devices where it is not required/wanted.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Need a fast way to switch to 31khz low power oscillator

Post by Kenrix2 »

Thank you kersing, i just tried that and looking at the asm file it move's osccon =0x00;(in asm CLRF gbl_osccon) up about five instructions vs just adding a c code icon and typing it in. There are still about 40 instructions before it . Great idea though, and it gives me an idea on situations where i don't want (ansela = 0x00); and (anselb = 0x00;) at reset. I don't know how to edit the _startup file to just add to the top of that. I think that would solve the problem and the micro would at least start. Right now the power supply sees a almost dead short, the voltage won't go up high enough to start the micro. If i could get it to 31khz immediately the current draw would drop from about 150ua to 7.5ua. I need to be under 30ua.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Need a fast way to switch to 31khz low power oscillator

Post by kersing »

You could try to shift the code generated by boostc using the "-rb" linker option (menu "Chip"->"Compiler options"). You would need to create a 'bootloader' at address 0 to do what you need and jump to the boostc code that starts at a higher address.

To test I added "-rb 16" to the start of the Linker/Assembler parameters. The resulting ASM file now contains:

Code: Select all

	ORG 0x00000010
	GOTO	_startup
	ORG 0x00000014
	MOVLP 0x00
	GOTO	interrupt
	ORG 0x00000017
As you can see the generated code starts at address 0x10. Now you need a 'bootloader' that performs what you have in mind, not forgetting interrupts (for this chip) jump to address 4 so you need to include provisions to forward the interrupt to the correct address. Using -rb <n> adds the offset n to the place the interrupt code is stored as well.

I think something like this should work:

Code: Select all

	ORG 0x00000000
	CLRF gbl_osccon
	GOTO	0x00000010
	ORG 0x0000004
	MOVLP 0x00
	GOTO	0x00000014
Somehow you need to translate this to hex and load it.

Good luck!
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Need a fast way to switch to 31khz low power oscillator

Post by Kenrix2 »

This works great kersing, since there were only a few lines of code in the bootloader I just looked up the binary in the device data sheet and converted to hex with a calculator. It came out to this:

0021 0199 2810 3FFF 3180 2814

Using the PICkit2 I imported my program hex file from Flowcode and then just typed the above numbers into the PICkit2 programmer window starting at location zero.

I can hardly believe it is working but the micro starts. It does take about 40ms to start but, that's acceptable. Thanks so much for the help and I am now playing with a (Smart) optically isolated input photodiode MOSFET controller. As you can tell I am very excited.

Post Reply