UK Vintage Radio Repair and Restoration Powered By Google Custom Search Vintage Radio and TV Service Data

Go Back   UK Vintage Radio Repair and Restoration Discussion Forum > General Vintage Technology > Hints, Tips and Solutions (Do NOT post requests for help here)

Notices

Hints, Tips and Solutions (Do NOT post requests for help here) If you have any useful general hints and tips for vintage technology repair and restoration, please share them here. PLEASE DO NOT POST REQUESTS FOR HELP HERE!

Closed Thread
 
Thread Tools
Old 12th May 2025, 8:19 pm   #21
Phil__G
Octode
 
Join Date: Mar 2011
Location: North Yorkshire, UK.
Posts: 1,476
Default Re: 50hz LED Arduino

Worth remembering, a mains neon does 100hz, a neon & a diode 50hz (Keep It Simple!!!)
Phil__G is offline  
Old 13th May 2025, 10:56 am   #22
Charles C
Triode
 
Join Date: May 2025
Location: Newcastle upon Tyne, Tyne and Wear, UK.
Posts: 32
Default Re: 50hz LED Arduino

Quote:
Originally Posted by TonyDuell View Post
What does the Arduino code to do it look like and it is portable to all Arduino boards?
Looks like I'm probably the least knowledgeable in this thread

but that would be fairly easy I think.

You would read a pin high or low and use an if else statement to have it switch values accordingly.

I would just use the tone function in the original example, no extra libraries needed.

I can write this up and copy to here if you like

The code would be pretty much transferable but you may have to check pin designations between boards, you need a pwm pin for the tone function, pretty much any pin will do for the switch
Charles C is offline  
Old 13th May 2025, 11:20 am   #23
TonyDuell
Dekatron
 
Join Date: Jun 2015
Location: Biggin Hill, London, UK.
Posts: 6,063
Default Re: 50hz LED Arduino

Except that tone doesn't generate 1:15 mark space ratios, does it? And the overhead of checking the switch will cause a slight timing error. It may be slight, but that's what I want to avoid
TonyDuell is online now  
Old 13th May 2025, 11:52 am   #24
Charles C
Triode
 
Join Date: May 2025
Location: Newcastle upon Tyne, Tyne and Wear, UK.
Posts: 32
Default Re: 50hz LED Arduino

[QUOTE=Charles C;1702273][QUOTE=TonyDuell;1702149]
Looks like I'm probably the least knowledgeable in this thread
QUOTE]

See it's true! you're right its a fixed 50% duty cycle on that function
Charles C is offline  
Old 13th May 2025, 12:04 pm   #25
TonyDuell
Dekatron
 
Join Date: Jun 2015
Location: Biggin Hill, London, UK.
Posts: 6,063
Default Re: 50hz LED Arduino

From a quick glance at the documentation, it appears :

You either use tone() which uses the hardware divider and thus the frequencies are likely to be right if the crystal is but which forces you to have a 1:1 mark-space ratio or you toggle a port pin and put in the delays which means your timing won't be spot-on (due to the overheads in the instructions to access the output port pin, read the rate-select input pin, select the right delay etc).

It doesn't apply here, but what does tone() do if you ask for a frequency which is not an integer division of the crystal frequency?
TonyDuell is online now  
Old 13th May 2025, 2:10 pm   #26
SiriusHardware
Dekatron
 
Join Date: Aug 2011
Location: Newcastle, Tyne and Wear, UK.
Posts: 13,785
Default Re: 50hz LED Arduino

I suspect it simply 'loses' the bit after the decimal point, if it even lets you compile the line with a floating point value in there, and generates as close an approximation to the requested round-number tone as it can, the resolution being determined by the clock frequency and the resulting smallest time-step interval available from the hardware timer.

If you went to assembly language you could take direct control of the hardware timer in the underlying micro and have it auto-run and reload, generating interrupts at a frequency of 16 x the frequency of interest, again subject to the smallest slice of time resolution that the clock frequency and the hardware timer, combined, can provide.

On interrupt 1 (of 16) you'd take the tone output high, and on interrupt 2 (of 16) you'd take the tone output low. On the remaining interrupts per cycle of the output waveform, no action. That would give you the 1/16th on, 15/16ths off ratio you want.

But as soon as you go direct to the hardware, the code (potentially) becomes one Arduino model specific.
SiriusHardware is offline  
Old 13th May 2025, 4:43 pm   #27
Buzby123
Heptode
 
Buzby123's Avatar
 
Join Date: Oct 2011
Location: Culcheth, Cheshire, UK.
Posts: 772
Default Re: 50hz LED Arduino

I don't know much about Arduino, but if it's anything like other micros I've used, then PWM is the way to do it.

All the PWM counting hardware is built in the chip, so once started the PWM continues unaffected by whatever the main code is doing.

It should be easy to set a 50Hz period with a 15:1 duty cycle.
__________________
https://www.tenacious.org.uk/
Buzby123 is offline  
Old 14th May 2025, 8:09 am   #28
SiriusHardware
Dekatron
 
Join Date: Aug 2011
Location: Newcastle, Tyne and Wear, UK.
Posts: 13,785
Default Re: 50hz LED Arduino

Arduino has a function for PWM output ( analogWrite() )but without looking I can't tell you whether it allows setting of the PWM frequency, it may use a fixed PWM output frequency with only the mark /space ratio variable.

Its main purpose in Arduino is to output a PWM equivalent of a numeric value so that it can (with a following filter) be used as a form of analogue voltage output.

As before, you could probably access the registers directly and set your preferred PWM frequency and mark/space ratio, but again that would make the code Arduino model specific and not very portable.

Last edited by SiriusHardware; 14th May 2025 at 8:16 am.
SiriusHardware is offline  
Old 14th May 2025, 9:47 am   #29
SiriusHardware
Dekatron
 
Join Date: Aug 2011
Location: Newcastle, Tyne and Wear, UK.
Posts: 13,785
Default Re: 50hz LED Arduino

This article initially looks promising, but then fails to explain the significance of the values pushed into certain low-level registers.

https://www.electronicwings.com/users/sanketmallawat91/proje...changing-of-pwm-pins-of-arduino-uno

It does however provide a sufficient lead that you could work out the rest by looking at the datasheet for the underlying Micro on your specific Arduino.

I think it's a bad omission not to have an option (in the Arduino analogWrite() function) to set the PWM frequency, if you were using the PWM output to control motor speed via some kind of H-driver IC for example, you'd probably want the PWM frequency to be in a specific range which wouldn't stress the motor and driver out too much.
SiriusHardware is offline  
Closed Thread

Thread Tools



All times are GMT. The time now is 5:34 am.


All information and advice on this forum is subject to the WARNING AND DISCLAIMER located at https://www.vintage-radio.net/rules.html.
Failure to heed this warning may result in death or serious injury to yourself and/or others.


Powered by vBulletin®
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright ©2002 - 2025, Paul Stenning.