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.

elapsed timer?

Status
Not open for further replies.
When I was working on the magic switchboard I intended to use the ADC to detect if the bulbs were out of circuit. Mike/Pommie (i think) showed me that I could do without the ADC.

Could the same be true here? You are not interested in the voltage in an analog sense. Only true above or false below. By setting up the voltage divider correctly you should be able to get the 1 to zero transition to happen at the voltage you are interested in.

If it works it would be handy on a uC with no ADC. Not having to wait on the ADC would give you just a bit more time.
The 18F's I've looked at (18F248 and 18F1320) have a Low-Voltage Detect module. My clock/thermometer uses the 248, so I think I'll experiment with that. My test breadboard with 16F876 doesn't have the LV Detect module, so I did it with A/D.

Could probably do it with a comparator too.
 
As 3v0 says, you can just use a digital input
Ya, after posting that I realized what he meant. :eek: It'll work better than the LV module too. That's meant more for battery powered devices.

It occurred to me as well that this isn't the perfect solution for my clock anyway, as it would save the date just fine (power outages here are rarely very long - usually just blips), but would lose time while the power is out. A proper battery backup is the solution. I'd still sense power loss, but would use that to shut down all unnecessary stuff and go to low power mode on a battery or batteries until power is restored.
 
As 3v0 says, you can just use a digital input.
So I put the power sensing wire on RB0 and set up the INT0 interrupt to write $55's to EEPROM on an INT0 falling edge. Now it writes 123 bytes to EEPROM before the power runs out. So performance isn't improved at all over sensing with A/D.

It occurred to me that my unused power supply on the breadboard had a 10uF cap that might be altering the response speed, so I replaced it with a couple wires and tested again. Now it writes 126 bytes to EEPROM when the power line is pulled.

For anyone who's interested, here's the code:
Code:
#include "eep.h"

void main(void)
{
	int x;
	trisb=0x01;
	option_reg=0b10001000;
	intcon=0b00010000;
	eecon1.EEPGD=0;				//clear EEPGD - point to EEPROM data memory
	eecon1.WREN=1;				//enable writes
	for(x=0;x<256;x++){			//erase EEPROM to $ff
		while(eecon1.WR);
		eeadr=x;
		eedata=0xff;
		eecon2=0x55;
		eecon2=0xaa;
		eecon1.WR=1;
	}
	intcon.GIE=1;
	eecon1.WREN=0;
	while(1){
		delay_s(1);
	}
}

void interrupt(void)
{
	int x;
	eecon1.EEPGD=0;
	eecon1.WREN=1;
	intcon.GIE=0;
	for(x=0;x<256;x++){			//write $55's to EEPROM
		while(eecon1.WR){}
		eeadr=x;
		eedata=0x55;
		eecon2=0x55;
		eecon2=0xaa;
		eecon1.WR=1;
	}
	intcon.INTF=0;
	intcon.GIE=1;
	eecon1.WREN=0;
}

and header file:
Code:
#include <system.h>
#include <stdio.h>
#pragma CLOCK_FREQ 18432000
#pragma DATA _CONFIG, _WDT_OFF & _HS_OSC & _LVP_OFF
 
Last edited:
Thank you everyone for all the help, sorry I didn't reply earlier I actually had major computer problems which ended up me getting a new one.
I like all the ideas, and especially the ones involving using a cap to "hold the power" long enough to write to the eeprom.
I'm still not completely conversane on how you actuallyl do it, but I'm going to start working on it again soon once I have everything else up and running properly, although it's not such a high priority now as before, I now have a new idea on my mind but I'll start a new thread about it!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top