Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:54 06 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MX170: PWM resolution

     Page 1 of 3    
Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 03:52pm 12 Feb 2022
Copy link to clipboard 
Print this post

this is probably one for Geoff:

i'm looking at an application that requires a single PWM output with precise (and as high resolution as possible) duty cycle. the duty cycle will be taken from a calibration (lookup) table, indexed on temperature. any temperature change will be relatively slow. the PWM frequency will be fixed, at a few hundred hertz.

ideally, i'd like 16-bits of resolution for the duty cycle, but can work with a bit less if needsbe  

it looks like PWM offers around 10-bits of resolution for frequencies less than 25kHz. while SERVO provides close to 12-bits (i'm assuming at the default 50Hz).


my question is: is there a 1:1 formula for converting between a continuous range of integer values (ie, 1,2,3,...)  and the percentage (for PWM) or pulse width in ms (for SERVO?


if not (or as an alternative), would it be possible for the PWM and/or SERVO command(s) to be modified in the next release so that they can accepted a NEGATIVE parameter value, where the negative value is interpreted as an actual count value (+ve) to be loaded into the PWM's counter?

the starting and ending values do not matter, just as long as they are continuous abd be so be used to arrive at an index into a lookup table.


cheers,
rob   :-)
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 12:20am 13 Feb 2022
Copy link to clipboard 
Print this post

Crazy idea but what about one of @Grogster's Propeller backpacks (or make your own)

Bump it up from 80MHz to 100MHz and you can have multiple 16bit PWMs @1.5KHz.


Micromite Companion Manual (draft).pdf

The P2 chip can generate 16bits at much higher frequencies via dithering.

Edit: OneDrive link for all software and firmware


Craig
Edited 2022-02-13 10:36 by Tinine
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 06:13am 13 Feb 2022
Copy link to clipboard 
Print this post

the simple solution is to use an external 16-bit or dual 12-bit DAC, but i'm interested in the possibility of just the MX170 (+ a DS18B20) doing all the work. another (less flexible) option is to simply do it all with an ATmega328p (ie, an arduino).

btw, this is to temperature compensate the output of an AD587 "High Precision 10v Reference". The AD587 has a rated maximum 5ppm/C temperature drift, and i'm looking at compensating over the range 10 to 35 degrees C.


cheers,
rob   :-)
Edited 2022-02-13 16:13 by robert.rozee
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:42am 13 Feb 2022
Copy link to clipboard 
Print this post

Considering the relatively slow update requirements, I was wondering if one could use SETTICK, toggling the lsb to provide the in-betweeny values?

Then again I could be typing out of my posterior  

Craig
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 07:59am 13 Feb 2022
Copy link to clipboard 
Print this post

  Tinine said  Considering the relatively slow update requirements, I was wondering if one could use SETTICK, toggling the lsb to provide the in-betweeny values?


the on/off ratio needs to be extremely precise and consistent, especially if i need to use two PMW channels of 10-bits each. alas, i can't see a SETTICK event handler being able to achieve this.


cheers,
rob   :-)
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5742
Posted: 08:03am 13 Feb 2022
Copy link to clipboard 
Print this post

I know there's a way to work out maximum PWM resolution at a given frequency and clock speed (I think) but for the life of me I can't remember it now. :(  For PWM at a few hundred Hz the limitation is probably the number of bits available to the command. That, I don't know, and I can't see it in the manual (for the Micromite or for the PicoMite). I'm probably missing something obvious, as usual. :)

If you want precision the PicoMite may be a better choice, Rob. Especially since a PIO can produce precision square waves and should be easy enough to make a very precise PWM port. I think there's an example of how to do it in the RP2040 Datasheet, actually.
Edited 2022-02-13 18:06 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:08am 13 Feb 2022
Copy link to clipboard 
Print this post

Clock frequency / resolution

In my example above: 100_000_000 / 65_536 = 1_526 Hz
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3558
Posted: 08:08am 13 Feb 2022
Copy link to clipboard 
Print this post

If you want to build an oven around the reference, you do not need speed. If you want to compensate the drift by adding an offset, you may need the bandwidth, but probably not the resolution. When the drift is 10mV then that is the range you need to compensate, and with 8 bit resolution you bring it back below 1% of the listed drift.

You could even do that with a ladder DAC at 8 mx170 pins.
Anyway it is not needed to have more resolutio in the DAC then on your input signal (the temperature). When temperature is +/- 0.1 degree over 25 degrees range, then that is 250 steps. No need for more than 250 steps in the output. Unless it is highly non-linear.

Volhout

P.s. I also liked the option to directly read ADC values, and output PWM values. Not the adapted values, 0-3.3v and 0-100%
Maybe an OPTION RAW
Edited 2022-02-13 18:13 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:18am 13 Feb 2022
Copy link to clipboard 
Print this post

  robert.rozee said  
  Tinine said  Considering the relatively slow update requirements, I was wondering if one could use SETTICK, toggling the lsb to provide the in-betweeny values?


the on/off ratio needs to be extremely precise and consistent, especially if i need to use two PMW channels of 10-bits each. alas, i can't see a SETTICK event handler being able to achieve this.


cheers,
rob   :-)


I was thinking of a 1ms interrupt which I find to be pretty deterministic (other code not blocking interrupts)

Thinking 5 different sample states would give you 200 Hz:

5 samples with lsb high
OR
4 samples with lsb high and 1 samples with lsb low
OR
3 samples with lsb high and 2 samples with lsb low
OR
2 samples with lsb high, etc.

Sounds like you're low-pass filtering?


Craig
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 08:40am 13 Feb 2022
Copy link to clipboard 
Print this post

Rob

The PicoMite will give you up to 16bits accuracy on PWM depending on the frequency selected. Attached is the code. From this you should be able to pick a combination of CPU clock frequency and PWM frequency to give you the full 16 bits of accuracy. All the calcs are double precision floating point so plenty of accuracy there

  Quote      MMFLOAT frequency=getnumber(argv[2]);
   if(frequency>(MMFLOAT)(CPU_Speed>>2)*1000.0)error("Invalid frequency");
   if(*argv[4]){
       duty1=getnumber(argv[4]);
       if(duty1>100.0 || duty1<0.0)error("Syntax");
   }
   if(argc==7){
       duty2=getnumber(argv[6]);
       if(duty2>100.0 || duty2<0.0)error("Syntax");
   }
   int wrap=(CPU_Speed*1000)/frequency;
   if(duty1>=0.0)high1=(int)((MMFLOAT)CPU_Speed/frequency*duty1*10.0);
   if(duty2>=0.0)high2=(int)((MMFLOAT)CPU_Speed/frequency*duty2*10.0);
   while(wrap>65535){
       wrap>>=1;
       if(duty1>=0.0)high1>>=1;
       if(duty2>=0.0)high2>>=1;
       div<<=1;
   }
   if(div>256)error("Invalid frequency");
   wrap--;
   if(high1)high1--;
   if(high2)high2--;
   pwm_set_clkdiv(slice,(float)div);
   pwm_set_wrap(slice, wrap);
   pwm_set_chan_level(slice, PWM_CHAN_A, high1);
   pwm_set_chan_level(slice, PWM_CHAN_B, high2);

 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 09:37am 13 Feb 2022
Copy link to clipboard 
Print this post

  Volhout said  If you want to build an oven around the reference, you do not need speed. If you want to compensate the drift by adding an offset, you may need the bandwidth, but probably not the resolution. When the drift is 10mV then that is the range you need to compensate, and with 8 bit resolution you bring it back below 1% of the listed drift.


compensation is down to the 1ppm level, that is a 10uV or less shift of the reference's output. the trim voltage (0-10v) is not simply added/subtracted, but instead fed (via a high-value series resistor) into a TRIM pin that itself can at most shift the AD587's output by just a few hundred millivolts. combined with the effect of the series resistor, this leaves a trim range of a few hundred microvolts.

have a look at:
https://www.analog.com/media/en/technical-documentation/data-sheets/AD587.pdf

peter: very much appreciate the code. unfortunately the pico generates too much electrical noise for this application. the business-end of the compensation electronics is itself powered from the output of the AD587; if i were to try using a pico i'd need a separate battery supply for it, and an optical link between pico and reference.


cheers,
rob   :-)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 09:46am 13 Feb 2022
Copy link to clipboard 
Print this post

Rob

If you want to use the MM2 then a pretty simple CFunction could do what you want or even poke the registers from Basic
Edited 2022-02-13 19:49 by matherp
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 10:04am 13 Feb 2022
Copy link to clipboard 
Print this post

within the existing firmware, i could see a couple of options:

(1) reverse-engineer the PWM source code to create a table of fractional numbers that corresponded to each step of the PWM resolution for a given frequency, then select values from that table.

(2) initiate the PWM using the usual means, then poke values directly into the PWM registers directly to change the pulse width.
(peter: oops, you edited your reply as i wrote this)

both are inelegant, but easier than creating a cfunction.


addendum:
or (C) modify the source myself, but then only for my own use.


cheers,
rob   :-)
Edited 2022-02-13 20:11 by robert.rozee
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:23am 13 Feb 2022
Copy link to clipboard 
Print this post

Rob

MX170?
Need low-level control using BASIC?
Need MUCH faster execution?
Real interrupt handling?


What Is It - ByPic.pdf


Craig
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 12:51pm 13 Feb 2022
Copy link to clipboard 
Print this post

  Tinine said  MX170?
Need low-level control using BASIC?
Need MUCH faster execution?
Real interrupt handling?

What Is It - ByPic.pdf


the main requirements are low electrical noise and hardware PWM that does not glitch. MMbasic on an MX170 fulfills this. the basic program running things normally sits in a trivial loop, checking the temperature of a DS18B20 and then adjusting the PWM value(s) as appropriate.

however, there will also be a set of calibration routines present, that will be somewhat more complicated. during the calibration process these routines will control a thermal chamber, collect voltage readings from a 34401A DMM, and construct the necessary correction table(s).

once these tables have been built (over several thermal cycles and a number of hours) they will be outputted to the console as 'data' statements, to be pasted back at the end of the program by the user.


the target audience are metrologists who live here: https://www.eevblog.com/forum/metrology/
generally elderly retired gentlemen who are not overly computer-literate. at the moment the usual approach is a string of thermistors, along with a diode or two, with just the very occasional use of a small PIC programmed in assembly.


cheers,
rob   :-)
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 01:04pm 13 Feb 2022
Copy link to clipboard 
Print this post

Just trying to get my head around anything thermal related would need such frequent updates...things change that quickly?

Craig
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 01:39pm 13 Feb 2022
Copy link to clipboard 
Print this post

the DS18B20 can resolve down to 1/16th of a degree C, and you can see that sort of temperature change being induced, for instance, by sitting something in the sun after just a few seconds. similarly for a chill breeze as a door is opened. at that resolution the DS18B20 can complete a measurement in a little under a second.

another thing, determined experimentally, is how repeatable the thermal response curve of an AD587 is. one may need to cycle from 'cold' to 'hot' and back again quite a few times to arrive at a good 'average' response curve. that curve will, of course, be completely unique to every AD587, and as a unit ages may even change. the units i have myself are all in ceramic packages, which helps.

so i'm aiming for tracking in the region of a 1 second interval, and to a fraction of a degree. both seem reasonable starting points. as for temperature range, less than 10 degrees C is uncomfortable, as is anything over 35, and one is unlikely to want to be calibrating precision equipment in uncomfortable conditions!


cheers,
rob   :-)
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5742
Posted: 02:03pm 13 Feb 2022
Copy link to clipboard 
Print this post

ByPIC hasn't been around for quite a while now, Craig. It doesn't seem to have any support and doesn't seem to be available for download any more. bypic.com is up for sale.

I'm not sure that poking data registers is all that inelegant. After all, the lookup table will be data statements, I assume, so an additional data field for the output makes sense.

If the resolution of PWM is 0.1% and the range is 0-100% then scaling an integer input to 0-1000 to get the PWM setting would seem possible, as it can't need an integer for PWM if it can be set fractionally.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3019
Posted: 02:37pm 13 Feb 2022
Copy link to clipboard 
Print this post

  robert.rozee said  the DS18B20 can resolve down to 1/16th of a degree C

I see a lot of dithering at 1/16th of a degree C. I don't see that anything less than a change of about 1/2 of a degree C is likely to be meaningful for many situations--maybe 1/4th of a degree if your environment is well-controlled.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 02:42pm 13 Feb 2022
Copy link to clipboard 
Print this post

Mick,

Someone brought it back to life  (no clue what "gpeasy" means though.)

As far as I'm concerned, it's a finished product. There is enough sample code and documentation that I can use it to great effect. I haven't found anything that needs fixing.

@40MHz, it runs an empty for-next, > 1.2M times/second

I particularly like the tasking/scheduling where I stick my process in a 1ms task, run the process and I still have a live command prompt, allowing me to check/modify variables or read/write registers, during execution.

In cases such as mine, if I need to make a change to the code, it can be a real drag to have to stop a sophisticated machine.

Just another weapon in my arsenal. Wouldn't recommend it if I didn't think it could get someone over a hurdle like it has, many times for me  
Edited 2022-02-14 00:45 by Tinine
 
     Page 1 of 3    
Print this page
© JAQ Software 2024