uController for Amp

What people are working on at the moment
User avatar
Nick
Site Admin
Posts: 13629
Joined: Sun May 06, 2007 10:20 am
Location: West Yorkshire

#31 Re: uController for Amp

Post by Nick »

Yep, generally much in controller land is done in interrupts. For timers, you have two or three hardware timers on chip. Pick one, setup its registers to take a divided clock input from your processor clock (16Mhz say). Set the divider for it to say 64. So the timer gets a 250k clock. Set the count register to 250. enable the interrupt. Then without doing anything more your interrupt routine is called once every milisecond. In the interrupt service routing, increment a short (2 bytes) counter. Every time the counter gets to 1000 increment a second counter. You will now be counting seconds. Every 10 ticks, you could read your inputs lines, and if needed feed them through filtering. For the analogue inputs, set up the ADC, then pick another timer, set that to interrupt at your required sample rate. Set the ADC to be triggered by that timer, and set the ADC to interrupt when its finished a sample. In that service routine read the ADC value. I like to write value like the ADC into a circular buffer, then in a loop in your non IRC code (main in C, or a function called from main), see if there is a value available in the buffer if there is read it and process it. I like to process input state changes into events in a buffer as well, then the main program can be event driven by reading values from that buffer.

And so on. You can get a lot more complex by adding a RTOS on the thing, but for tiny processors like this there is normally no space or need.

All the bits of hardware built into the chip can do most of the heavy lifting if you let them and the code ties it all together. The timers for example can do a lot more like producing a PWM value without you having to do much than load the value you want.
Little known fact, coherent thought can destructively interfere with itself leaving no thought at all, that’s why I prefer incoherent thought.
izzy wizzy
Old Hand
Posts: 1365
Joined: Fri Nov 02, 2007 7:02 pm
Location: Auckland NZ
Contact:

#32 Re: uController for Amp

Post by izzy wizzy »

After your last post, got all excited about registers, timers (Arduino has 3) and clocks and stuff as could glean a way ahead. Did a whole bunch of reading and then found that Arduino has a function millis() which returns milliseconds board has been up and running and uses timer0. Reckon that largely takes care of what I'm trying to do on that front within reason of course.

Hopefully I'm still left with ring buffer for reading ADC I/O and all that. Pointers are a thing that I find scary for some reason; a mental block on them. There's a function in there analogRead() as well but that will have to be finessed a bit for what I want. My programming skills (lack of) largely shielded me from pointers so maybe that's why I find them scary.
User avatar
Nick
Site Admin
Posts: 13629
Joined: Sun May 06, 2007 10:20 am
Location: West Yorkshire

#33 Re: uController for Amp

Post by Nick »

AHH i forgot you were using Arduino. Never actually used it sounds like it hides all the bits I like but that may be for the good if you are not fluent in C.
Little known fact, coherent thought can destructively interfere with itself leaving no thought at all, that’s why I prefer incoherent thought.
User avatar
jack
Eternally single
Posts: 4306
Joined: Wed Dec 29, 2010 8:58 pm
Location: ɐılɐɹʇsnɐ oʇ ƃuıʌoɯ ƃuıɹǝpısuoɔ
Contact:

#34 Re: uController for Amp

Post by jack »

I have an early edition if the O'Reilly Arduino Cookbook by Michael Margolis that you are welcome to have just for p&p (I also have a later edition so it's no use to me). Over 600 pages of goodness!

It's a great introduction to getting started with Arduino and how to use the libraries for practical projects.

Let me know if you want it.
PXL_20210915_093425967_copy_756x1008.jpg
PXL_20210915_093425967_copy_756x1008.jpg (150.92 KiB) Viewed 216 times
Vivitur ingenio, caetera mortis erunt
izzy wizzy
Old Hand
Posts: 1365
Joined: Fri Nov 02, 2007 7:02 pm
Location: Auckland NZ
Contact:

#35 Re: uController for Amp

Post by izzy wizzy »

Thanks and I appreciate the offer. If I was still down the road in Kent, I'd be up for it but in NZ now and I looked up the postage; not far off a new book price here :shock:
User avatar
jack
Eternally single
Posts: 4306
Joined: Wed Dec 29, 2010 8:58 pm
Location: ɐılɐɹʇsnɐ oʇ ƃuıʌoɯ ƃuıɹǝpısuoɔ
Contact:

#36 Re: uController for Amp

Post by jack »

izzy wizzy wrote: Wed Sep 15, 2021 11:06 am Thanks and I appreciate the offer. If I was still down the road in Kent, I'd be up for it but in NZ now and I looked up the postage; not far off a new book price here :shock:
Fair enough! Auckland I see. Very nice!

Somehow I though you were still in the UK...
Vivitur ingenio, caetera mortis erunt
izzy wizzy
Old Hand
Posts: 1365
Joined: Fri Nov 02, 2007 7:02 pm
Location: Auckland NZ
Contact:

#37 Re: uController for Amp

Post by izzy wizzy »

As I haven't got any hardware yet, thought I'd look into simulation and found TinkerCad. It's very basic but has got me started doing some basic stuff. Got the cathode current display bit going which wasn't too taxing.

Assembled some sig gens to generate a "music" signal sort of thing to see the affect of AC on those sample points and to look at hardware signal conditioning and software sampling.

tinkercad.png
tinkercad.png (184.33 KiB) Viewed 157 times
User avatar
Nick
Site Admin
Posts: 13629
Joined: Sun May 06, 2007 10:20 am
Location: West Yorkshire

#38 Re: uController for Amp

Post by Nick »

Maybe we are living in the Matrix...
Little known fact, coherent thought can destructively interfere with itself leaving no thought at all, that’s why I prefer incoherent thought.
User avatar
ed
retired
Posts: 4696
Joined: Thu Jun 21, 2007 4:01 pm
Location: yorkshire
Contact:

#39 Re: uController for Amp

Post by ed »

Maybe we are living in the Matrix...
I don't think there's any fule proof method for finding out...

Sebastian persuaded me to take him to watch this last weekend....

cross between matrix and person of interest.....jolly wheeze all the same

https://www.imdb.com/title/tt6264654/
There's nowhere you can be that isn't where you're meant to be
izzy wizzy
Old Hand
Posts: 1365
Joined: Fri Nov 02, 2007 7:02 pm
Location: Auckland NZ
Contact:

#40 Re: uController for Amp

Post by izzy wizzy »

So far this is going well in The Matrix.

Was wondering if it's feasible to hold up the Arduino long enough with a supercapacitor to write the hourmeter to EEPROM in case of a random turn off.

Normally it would be a managed turn off which would trigger the turnoff function but in case of power failure, something could hold the Arduino board only up long enough to complete that function. Trying to avoid battery backup but if I have to, that could work as well.
User avatar
jack
Eternally single
Posts: 4306
Joined: Wed Dec 29, 2010 8:58 pm
Location: ɐılɐɹʇsnɐ oʇ ƃuıʌoɯ ƃuıɹǝpısuoɔ
Contact:

#41 Re: uController for Amp

Post by jack »

izzy wizzy wrote: Sat Sep 18, 2021 7:47 am So far this is going well in The Matrix.

Was wondering if it's feasible to hold up the Arduino long enough with a supercapacitor to write the hourmeter to EEPROM in case of a random turn off.

Normally it would be a managed turn off which would trigger the turnoff function but in case of power failure, something could hold the Arduino board only up long enough to complete that function. Trying to avoid battery backup but if I have to, that could work as well.
You might, but it may just be an over-complication (you'll need to add brown/black-out detection) and prone to error - it's a multi-byte write so takes (in uP terms) a while - MSB first -> LSB last... You could add a small Li-ion backup which is available as an Arduino shield (you'd still need to detect the mains power fail somehow).

I mean, you could add a DS3231 (*) easily enough (there's an Arduino library for that) which would give you stupidly accurate timing and you can get breakout boards for it, including the clock backup battery. But, really?

Personally, I'd stick with the "engineering solution" of adding cycle count/2 - it's simple and when the life of a valve is measured in 1,000s of hours, likely to be easily accurate enough, especially as the concept of "life of a valve" is pretty abstract and prone to a huge amount of variation, even with a single type.

It's like the clocks I make - they're accurate to milliseconds or better... but why? Nobody really cares - 99% of the time (!) a few minutes either way would be just fine...

(*) this is the chip that most folk use as the RTC in nixie clocks etc. It's an astonishing device, but there are a lot of fakes on eBay etc.
Vivitur ingenio, caetera mortis erunt
User avatar
Nick
Site Admin
Posts: 13629
Joined: Sun May 06, 2007 10:20 am
Location: West Yorkshire

#42 Re: uController for Amp

Post by Nick »

Yep, I agree its a solution in search of a problem. But the simple way is to generate a pulse train from the incoming AC. An opto and diode on the transformer secondary would do that. I would then set a timer to count to and trigger in 30ms, then zero the timer count with each 20ms mains pulse. If the timer triggers then you are shutting down, You just need enough capacitance in the supply to keep it going. An ATTiny takes 3.4ms to write a byte to EEPROM so that gives you some idea how long the supply has to remain. a second or so should be more than enough.
Little known fact, coherent thought can destructively interfere with itself leaving no thought at all, that’s why I prefer incoherent thought.
User avatar
rowuk
Old Hand
Posts: 368
Joined: Sun Jun 01, 2014 2:50 pm
Location: Germany

#43 Re: uController for Amp

Post by rowuk »

I have often thought about his too. One of my first considerations was:
as long as everything is OK, do I have to write anything to local storage?
That lead me to the idea that what ever uController could just message something else if there was an issue. We do something similar at work with a linux implementation of NAGIOS.
This scenario could collect amplifier data at any interval, phono cartridge use (hours turned on with the lift in "down" position), Preamp status, UPS status, etc. I am pretty sure that anyone thinking about implementing something like this already has a server running somewhere...

This is a really interesting thread and has given me some paths to explore.
Whenever I feel blue, I start breathing again.
User avatar
Nick
Site Admin
Posts: 13629
Joined: Sun May 06, 2007 10:20 am
Location: West Yorkshire

#44 Re: uController for Amp

Post by Nick »

I must award you the overcomplicate award for 2021 :-). You have just added at least an rs232 cable to your server or more likely a tcpip stack and a network interface.
Little known fact, coherent thought can destructively interfere with itself leaving no thought at all, that’s why I prefer incoherent thought.
izzy wizzy
Old Hand
Posts: 1365
Joined: Fri Nov 02, 2007 7:02 pm
Location: Auckland NZ
Contact:

#45 Re: uController for Amp

Post by izzy wizzy »

Nick wrote: Sat Sep 18, 2021 12:17 pm I must award you the overcomplicate award for 2021 :-). You have just added at least an rs232 cable to your server or more likely a tcpip stack and a network interface.
I have just read this before I go to bed a bit drunk and it's given me a good giggle.
Post Reply