Go Down

Topic: tiny85 self power-off (Read 1 time) previous topic - next topic

JoshNZ

I know it's 2 I just don't know why or what the logic to that is. What arithmetic is happening to arrive there?

And yes but the 16 bit timer will mean millis is back to zero after 65535ms? Otherwise I have a problem that's disappeared for a reason I'm unaware of

6v6gt

The millis() function on an ATtiny85 actually uses an 8 bit timer, timer 0.
But that is irrelevant. An interrupt from the timer maintains a 32 bit counter with a rollover of approximately 50 days.

Maybe explain how you determined there was a rollover in your case.

As for the arithmetic.

Instead of 1 - 0xFFFFFFFF, imagine 1 - 0xFF  

0 - 0xFF is 1 because if you add 1 to 0xFF you get a rollover to 0  (assuming you are working with unsigned 8 bit values).
So 1 - 0xFF is 2 , 2 - 0xFF is 3  etc.


JoshNZ

I had set a while loop to run while millis() - prevmillis < period and I thought I saw it skip some of it but I was playing around with other stuff maybe I just got something wrong.
I changed prevmillis from an int to an unsigned long and whatever else I did, fixed it.

I'm not going to post my code, you guys don't need the stress  :D  :D. I couldn't get softwareservo or servo8bit libraries to work reliably and since the uC has no other functionality I've written PWM output with for loops. Too crude for this forum  :o

Thanks for the explanation! And thanks to all who chimed in. I'll post a pic when I get the finish on

6v6gt

#33
Aug 17, 2020, 12:51 pm Last Edit: Aug 17, 2020, 12:54 pm by 6v6gt
I had set a while loop to run while millis() - prevmillis < period and I thought I saw it skip some of it but I was playing around with other stuff maybe I just got something wrong.
I changed prevmillis from an int to an unsigned long and whatever else I did, fixed it.
. . .
millis() does skip some values because it is based on ticks of 1024uS, not 1mS. Some millisecond values simply get lost. For example, you never see a millisecond value of 42.
See https://www.best-microcontroller-projects.com/arduino-millis.html

However, if you were using an incorrect data type, that is more likely to have been the problem.

Paul__B

For example, you never see a millisecond value of 42.
HHGTTG?  :smiley-lol:

6v6gt

HHGTTG?  :smiley-lol:
I never thought of that, but that could well have inspired Douglas Adams.

JoshNZ

#36
Aug 18, 2020, 10:44 am Last Edit: Aug 18, 2020, 09:49 pm by JoshNZ
All finished up this evening, at long last. The wood is swamp kauri, always forget how nice a finish it takes.

I decided to have a go at etching a board rather than using perfboard and am super glad I did, what a neat little process. I'm delighted with the results for a first attempt. Unfortunately after all that discussion about the resistor being in the wrong place, I managed to take it from the right place on my breadboard then draw, and place it in the wrong place on the board =(. It does divide but I only lose .1v or so on the N channel gate by my math.





And a vid if anyone is interested.
https://youtu.be/xDmV8Vz2OVU
Thanks again for the responses

pmagowan

nice, has a good character

ShermanP

I think it's wonderful.  Well done.

larryd

Well we now need to see a video showing the actual operation ;).



No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

JoshNZ

Did you miss the YouTube link Larry? Or you mean under the hood. It's exactly what you'd expect there's not much to show, a servo for the lid and one for the arm. The head is stuck on the lid by a piece of tig wire holding it at the right angle hah

larryd

#41
Aug 18, 2020, 10:06 pm Last Edit: Aug 18, 2020, 10:20 pm by larryd
Yes, I didn't see the link.

Very funny.  + +

Going to make a few for Xmas presents this year.

Nice finish on the wood and box nice joints !



Will you copy the final sketch here and a final schematic ?






No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

JoshNZ

I would but, you'd find it funnier than the vid itself.

I'd rather you program it the way you would, then if I make a couple more for presents, I can use your sketch xD.
I would genuinely like to see how someone experienced would do it without libraries. I'm not super confident with timers and even if I was, strategically I don't know which bits would go in interrupt routines and the main loop.

Other than mine being a manual hack there are two reasons Id discourage it, one I discovered with these servos in particular I only need 2 pulses to make a servo track for and hold that position, for as long as it's powered up. So my for loops only iterate 3 times when max speed is allowable. And secondly my PWM wave form isn't strictly correct, the off time is fixed and not balanced with the on time for consistent period (i.e.. 20ms - on time). Both may cause other servos to fail or behave erratically. Lucky for me neither matter in this case.
These servos came out of a model helicopter, my guess is they have a "hold last position" function for if the RX fails.

I'll post the schematic when im at my computer later.

larryd

Normally when you succeed 'or not' you share your results plus or minus like others have shared with you in the previous 42 posts.

These forums are here to help others who come across this thread with the same questions.





No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

JoshNZ

#44
Aug 19, 2020, 05:21 am Last Edit: Aug 19, 2020, 06:34 am by JoshNZ
Sure, if it can be constructive I suppose but heed above advice as it will likely not work for most I guess...

The sketch and board layout reflects the fixed N-channels gate resistor and is not how mine is but, in any case...
Enjoy, with a grain of salt!

Actually one constructive thing I could add, I lightened my switch by swapping out the spring for one with less stiffness. I opened a few pens and found one that compressed easier. Cut to approx length then stretched until slop in switch was taken up. The servo struggled with the factory switch, but much snappier performance after this. I also machined an extension for the toggle knob, for leverage initially but it was probably not necessary. It does add to the look.

My only other thought is the hit switch function requires the switch to toggle for the function to complete (doing so improved response time). If someone unknowingly put their coffee on the box and bumped the switch, the servo would likely burn out and the circuit would run until batteries were flat. I thought I could timeout that function but that would disappoint the tough users who want to wrestle with the switch. You would only save the servo (not the batt), as there would be no way to power off the LDO with the switch held open, the best you could do is relax the servo then sleep the uC, and it'd require manually cycling. So I left as is. I'm sure there's a clever way around it.

Go Up