Start up procedure for 2 different modes

TLDR: How can i make a program that checks for 3 seconds long if a switch is press within those 3 seconds? And if the switch is not pressed in those 3 seconds it will go down another path in the software. WITHOUT MILLIS

Hello, i am designing a battery tester which tests the voltage of the battery under no load, and under load and calculates the internal resistance of the battery, but i need it to have 2 modes. The tester will have a RGB led, a LCD screen and a pushbutton switch

Mode 1: All the measured voltages are shown on the screen. Also the calculated internal resistance will be shown on the lcd screen. A green or red led will light up (depending if the internal resistance is in the marge of what it should be.

Mode 2: There will be no information on the lcd. The measurement will take place, and the red or green led will light up (depending if the internal resistance is in the marge of what it should be). This a faster test methode so more batteries can be tested in the same amount of time.

BUT, when you start up the batterytester there will be a question displayed on the LCD for 3 seconds. "Detail mode?" (Mode 1). If you press the button within those 3 seconds (doesnt matter when in those 3 seconds) the program will go to the detail mode where the information is shown on the lcd. If you dont press the button and the 3 seconds are over you will automaticcly go to the fast mode (mode 2).

My question is: Is it possible to program this without the use of millis()? I prefer only the delay function because my interrupt knowledge isnt very good and in the end i will make a professional device with a PIC microcontroller from Microchip (they dont have the millis function, or anything similar)

Killerpirate:
TLDR: How can i make a program that checks for 3 seconds long if a switch is press within those 3 seconds? And if the switch is not pressed in those 3 seconds it will go down another path in the software. WITHOUT MILLIS

The solution seemed easy until I came to the bit in capitals. Why not use millis() ?

...R

Killerpirate:
...

My question is: Is it possible to program this without the use of millis()? I prefer only the delay function because my interrupt knowledge isnt very good and in the end i will make a professional device with a PIC microcontroller from Microchip (they dont have the millis function, or anything similar)

You can check the button repeatedly in a loop with a bit of delay() in it, like check thirty times, checking every 100 milliseconds. Or 300 times every 10 milliseconds if my math is correct. You get the idea.

But you seem to have waded in a bit deep if you are of the opinion that any of what either millis() or delay() affords from a functional point of view cannot be easily done on a PIC microprocessor.

Using delay() in this special circumstance is no large deal, but you really should learn how to do without it. You will thank yourself for taking the time now. Don't, er, delay.

a7

Killerpirate:
My question is: Is it possible to program this without the use of millis()? I prefer only the delay function because my interrupt knowledge isnt very good and in the end i will make a professional device with a PIC microcontroller from Microchip (they dont have the millis function, or anything similar)

I missed this earlier - for some reason PIC was not mentioned in the TLDR

This is an Arduino Forum where programs are for Atmega microprocessors. It is not the place to get information about PIC programming.

The source code for the Arduino millis() function is readily available if you want to create a PIC equivalent.

And you can make a very professional product with an Atmega microprocessor - there are millions of them around.

...R

Robin2:
I missed this earlier - for some reason PIC was not mentioned in the TLDR

This is an Arduino Forum where programs are for Atmega microprocessors. It is not the place to get information about PIC programming.

The source code for the Arduino millis() function is readily available if you want to create a PIC equivalent.

And you can make a very professional product with an Atmega microprocessor - there are millions of them around.

...R

Thanks for your reply! At this point i am not asking any info about the PICs, im only saying that in the future the software will have to work on a PIC, with only minor changes.
Unfortunatly, i am forced to work with the PICs.

Killerpirate:
Unfortunatly, i am forced to work with the PICs.

I presume there are other Forums for people who play around with PICs.

...R

I cobbled my own millis for PIC, instead of trying to count milliseconds, it just sets the timer interrupt for the power of two which is close enough for blinky LEDS or pushbutton timing and debouncing... each "milli" is 1.024mS:

unsigned int approximillis(void) {
    unsigned int val;
    INTCONbits.GIE = 0; // disable global interrupts
    val = millis_timer; // capture timer value
    INTCONbits.GIE = 1; // enable global interrupts
    return val;
}

There's more... my intent was not to provide a solution, but to show that the millis() timing technique is indeed extremely portable.