Zanzal's Free Arduino/AVR Code

  • 102 Views
  • Last Post 29 August 2017
Zanzal posted this 22 August 2017

I am going to use this thread to post free code that others can use or customize as they wish. 

Attached is a software PWM snippet I worked on last night. The software PWM has some advantages over the Hardware PWM. It can be used to program more complex waveforms than the Arduino can normally produce and has good quality up to about 3 Khz. It will go higher, 100Khz+, but like any software PWM it has the usual limitations which is precision and the higher it goes the less precise the frequency and duty cycle you are requesting. I specifically wrote this one to produce as little "jitter" as possible. While it is not reasonable to expect a 16Mhz 8-bit device to produce perfect high frequency wave forms. It can be improved by running at higher Mhz and recoding it in assembly, however, there are limits to how perfect these improvements can be. Also, this is not the best implementation of a AVR software PWM, but rather it was the implementation that I needed for my purposes..

Attached Files

  • Liked by
  • Wistiti
  • Chris
Order By: Standard | Newest | Votes
Chris posted this 27 August 2017

Hey Zanzal - I have been working on a similar thing, not PWM as such, but what I call:

"***   Arduino Uni-Polar Parametric Switch V 1.0   ***"

I am using a few simple and very cheap components to detect peak current and trigger an On Pulse with in this time frame.

Early tests show some progress:

   

 

Of course, from our Parametric Research, we know why we are switching here:

 

There will be limits to my work, Read Time on the Analog Sensor will restrict the upper most frequency. 

Arduino is a great platform to experiment with, it is powerful and it is cheap. One could do what we have done for only a few dollars!

P.S: For those that don't know already, way back on: 10/01/2014 I published an article: Whats it going to take to Get OU? and also an Experiment: Paraformer or Parametric Transformers even earlier: 17/12/2013

This gives all the answers needed to understand the Parametric change in parameters needed. Including some basic math to see what sort of changes to look for. 

A more detailed post: Click Here

P.P.S: Nice Code!

   Chris

  • Liked by
  • Wistiti
  • Zanzal
Zanzal posted this 28 August 2017

That's awesome Chris. I wish I knew the basic electronics behind safely sending signals to the analog port of the arduino. Its one of the things on my todo list to figure out.. So much to do, so little time.

This weekend I wrote another Software PWM this time for the esp8266.  The problem with software PWMs is keeping the jitter down without blocking the CPU. The problem with the avr code I was using is the cpu is fully dedicated to the PWM. So if all one wanted to do was use the microcontroller for a pwm that might work, but it seems like such a waste when there is so much more it can do.

Assuming you can live with only one 10-bit analog port (or don't mind using a multiplexer) the ESP-12 is a couple bucks from Aliexpress. Its 32-bit and can be overclocked in firmware to 160MHz so it will not have issues with sample rate for frequencies in the high kHz. The ESP-32S is about $8 and has a ton of ports, dual core, etc. You can turn the wifi off on them to save power if not using it.

  • Liked by
  • Chris
Chris posted this 28 August 2017

Hey Zanzal - Keep Currents low and voltage within the analog port threshold all should be good.

The joys of single threaded MPU's or Code behind them makes multitasking difficult!

I went to the .NET Microframework for such tasks: https://www.ghielectronics.com/community/codeshare/entry/931

The thing is, the Teacher is always still a Student!

I will never stop Learning! I try to share what I have learned - You're right about Freeoresonance, it is Parametric Oscillations!

   Chris

  • Liked by
  • Zanzal
Zanzal posted this 28 August 2017

I know people really love their .NET in much the same way I love C++ and STL. Unfortunately, neither are particularly well suited for high performance micro-controller code. A single clock cycle at 160Mhz is 6.25ns. An interrupt can take several hundred clock cycles from the time the event is triggered until the handler begins to execute. There just isn't enough time to make everything nice and pretty. Its gotta be fast, no matter how ugly the code gets.

Atom + PlatformIO IDE plugin is the best I've found. Its a multi-framework IDE for C/C++ that supports Arduino, mbed, and others.. Its cross platform and works on Mac, Windows, and Linux.

When my ESP-32S arrives I'll try using the built-in hall sensor combined with a small inductor to measure the load current. We'll see if its that simple.

  • Liked by
  • Chris
Chris posted this 29 August 2017

Yes, this is true, .NET is not particularly fast, sad but true.

I will have to look into those IDE's thanks for the recommendations!

   Chris

  • Liked by
  • Zanzal
Close