<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent posts to Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/</link><description>Recent posts to Time for HPWM to Execute...420uS Sound Right?</description><atom:link href="https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/feed.rss" rel="self"/><language>en</language><lastBuildDate>Tue, 25 Aug 2020 18:34:48 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/feed.rss" rel="self" type="application/rss+xml"/><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#0ee7</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Please excuse my ignorance in my previous post.&lt;br/&gt;
I just thought take say 100 byte samples in am array and a 600hz interrupt to read the array repeatedly and then r-c filter to get 60Hz.&lt;br/&gt;
Silly. sorry.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">stan cartwright</dc:creator><pubDate>Tue, 25 Aug 2020 18:34:48 -0000</pubDate><guid>https://sourceforge.net4ffecc6e7c418b80e8c8acf9b898ebb4d92894b4</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#3813</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Another suggestion, try adding this to your code somewhere:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;@define&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;HPWM_FAST&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;With this, HPWM will store the last frequency used. If it is called again with the same frequency, it doesn't recalculate the period or the timer settings needed to give that period. That saves a few cycles. I think it's much the same as HPWMUpdate, as @Anobium suggested.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hugh Considine</dc:creator><pubDate>Tue, 25 Aug 2020 07:25:37 -0000</pubDate><guid>https://sourceforge.net77eb390497c7205721a9e6a73b9533160ddc521c</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#9a48/1b1c</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;That looks too much info for me. &lt;br/&gt;
I used hpwm with a 18f25k22 which I think has 2 hpwm pins for dc motor/hbridge inhibit pins&lt;br/&gt;
and it worked but not made sine waves to be honest.... and analogue circuits are so much hard sums.&lt;br/&gt;
My first thought would be to use read ad to sample half a real sine wave and store in an array &lt;br/&gt;
and some math to generate the other half of the wave. Or sample a whole cycle.&lt;br/&gt;
I tried to make a faster pic/uno glcd scope by sampling read ad to array then show display.&lt;br/&gt;
The array was 320 bytes or some division of the x axis of the glcd.&lt;br/&gt;
I use a 328 which has 2K ram.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">stan cartwright</dc:creator><pubDate>Mon, 24 Aug 2020 21:27:17 -0000</pubDate><guid>https://sourceforge.net0594b7c5c2044586e9e539584ab5048dc1b2ec82</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#9a48</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;I'm implementing the ideas in here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ww1.microchip.com/downloads/cn/AppNotes/cn012129.pdf" rel="nofollow"&gt;http://ww1.microchip.com/downloads/cn/AppNotes/cn012129.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The idea is to have a target frequency (Static for now, later variable with an a-d input), and chop it up into 18 'time slots'. Each time slot has a different DC PWM to simulate a point on the sine voltage curve. Pretty cool idea and works well. It's just that my times are being extended. With a 1ms/time slot I'd expect close to a 18ms sine wave, but it's up at 24 or something.&lt;/p&gt;
&lt;p&gt;Seems like I need to drill down and just adjust the DC register instead of setting up the whole HPWM again. I'll test to see how fast that is tonight.&lt;/p&gt;
&lt;p&gt;The chip I'm working with only has 2 HPWMs but i'm trying to prove the concept before bying a more appropriate chip.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Chay&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chay Foss</dc:creator><pubDate>Mon, 24 Aug 2020 20:16:12 -0000</pubDate><guid>https://sourceforge.net49a296dbf502b48214a551aa7a6379b69697ba91</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#aa73</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;I am getting the 20khz/50% duty cycle coming out as expected. There is no issue there. The issue is that to perform this function before the processor continues with other code.&lt;/p&gt;
&lt;p&gt;I don't have my code handy at the moment, but in the end I will need to change the duty cycle multiple times in a short period (Ie: max once per 500us or so)  in order to make the application work. I used 128 as a duty cycle  examle, but in the end the DC will read a variable like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;        &lt;span class="n"&gt;HPWM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PWM_Var&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;Enable&lt;/span&gt; &lt;span class="n"&gt;hardware&lt;/span&gt; &lt;span class="n"&gt;pwm1&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;chip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="n"&gt;kHZ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="n"&gt;pwm&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Here is the idea I used to see how long it's taking:&lt;/p&gt;
&lt;p&gt;startmain&lt;/p&gt;
&lt;p&gt;portc.0 = 1; set check pin true&lt;/p&gt;
&lt;p&gt;;other code here&lt;/p&gt;
&lt;p&gt;HPWM, 1,20, 128;  Set up the hpwm out&lt;/p&gt;
&lt;p&gt;portc.0 = 0&lt;br/&gt;
wait 10 ms&lt;/p&gt;
&lt;p&gt;goto startmain&lt;/p&gt;
&lt;p&gt;I monitored portc.0 with a 'scope. &lt;/p&gt;
&lt;p&gt;So with the hpwm commented out, the code executed quicly. With it in it was slow-to the point it was extending the intervals set in the other code.&lt;/p&gt;
&lt;p&gt;In the final code I will use T1 interrupt to drive the time intervals, and have it variable by presetting T1 to a certain value. At the moment I'm jst tryng to work out this issue though.&lt;br/&gt;
When I had it running faster and loading the sine values for DC, it worked great, just slow.&lt;/p&gt;
&lt;p&gt;I'll review your suggestions. thanks for the post.&lt;/p&gt;
&lt;p&gt;Chay&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chay Foss</dc:creator><pubDate>Mon, 24 Aug 2020 20:06:30 -0000</pubDate><guid>https://sourceforge.nete67aeaf91f835023ac6f7e9f0b8121eabe80f8e3</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#bdd5</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Do you need an interrupt as described here? &lt;a href="https://community.cypress.com/docs/DOC-17276" rel="nofollow"&gt;https://community.cypress.com/docs/DOC-17276&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">stan cartwright</dc:creator><pubDate>Mon, 24 Aug 2020 18:26:00 -0000</pubDate><guid>https://sourceforge.net9c05009ecdcf6a6686b0c0f65c8f23a0f7d737b1</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=250#73b0</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;You may want to consider this approach.&lt;/p&gt;
&lt;p&gt;Use the static PWM to setup the CCP/PWM and then change PR2.  This will may work for you.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;#&lt;span class="nv"&gt;chip&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="nv"&gt;F74&lt;/span&gt;
#&lt;span class="nv"&gt;option&lt;/span&gt; &lt;span class="nv"&gt;Explicit&lt;/span&gt;

  #&lt;span class="nv"&gt;define&lt;/span&gt; &lt;span class="nv"&gt;PWM_Freq&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;    &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Set frequency in KHz&lt;/span&gt;
  #&lt;span class="nv"&gt;define&lt;/span&gt; &lt;span class="nv"&gt;PWM_Duty&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
  &lt;span class="nv"&gt;PWMOn&lt;/span&gt;                  &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Turn on the PWM&lt;/span&gt;

  &lt;span class="nv"&gt;Dim&lt;/span&gt; &lt;span class="nv"&gt;FrequencyRange&lt;/span&gt; &lt;span class="nv"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;Byte&lt;/span&gt; &lt;span class="nv"&gt;Alias&lt;/span&gt; &lt;span class="nv"&gt;PR2&lt;/span&gt;

  &lt;span class="k"&gt;Do&lt;/span&gt;
      &lt;span class="k"&gt;For&lt;/span&gt; &lt;span class="nv"&gt;FrequencyRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;
          &lt;span class="k"&gt;wait&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="nv"&gt;ms&lt;/span&gt;
      &lt;span class="k"&gt;Next&lt;/span&gt;
  &lt;span class="k"&gt;Loop&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anobium</dc:creator><pubDate>Mon, 24 Aug 2020 08:23:12 -0000</pubDate><guid>https://sourceforge.net751ab9e5d11e6f12b4cd3b500680f21cea2b826f</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=250#aaae</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;@Chay.&lt;/p&gt;
&lt;p&gt;Not sure I get the issue here.  Some code may help me understand.  Are the issues?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;HPWM 1,20,128 does not generate a frequency of 1mHz?  As in&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;#&lt;span class="nv"&gt;chip&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="nv"&gt;F74&lt;/span&gt;

&lt;span class="nv"&gt;HPWM&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;,&lt;span class="mi"&gt;20&lt;/span&gt;,&lt;span class="mi"&gt;128&lt;/span&gt;

&lt;span class="k"&gt;Do&lt;/span&gt;
&lt;span class="k"&gt;Loop&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;The update process is slow?  As in&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;#&lt;span class="nv"&gt;chip&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="nv"&gt;F74&lt;/span&gt;
#&lt;span class="nv"&gt;option&lt;/span&gt; &lt;span class="nv"&gt;Explicit&lt;/span&gt;

&lt;span class="nv"&gt;HPWM&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;,&lt;span class="mi"&gt;20&lt;/span&gt;,&lt;span class="mi"&gt;128&lt;/span&gt;

&lt;span class="nv"&gt;Dim&lt;/span&gt; &lt;span class="nv"&gt;DutyRange&lt;/span&gt; &lt;span class="nv"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;Byte&lt;/span&gt;

&lt;span class="k"&gt;Do&lt;/span&gt;
    &lt;span class="k"&gt;For&lt;/span&gt; &lt;span class="nv"&gt;DutyRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
      &lt;span class="nv"&gt;HPWMUpdate&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;,&lt;span class="nv"&gt;DutyRange&lt;/span&gt;
      &lt;span class="k"&gt;Wait&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="nv"&gt;ms&lt;/span&gt;
    &lt;span class="k"&gt;Next&lt;/span&gt;
&lt;span class="k"&gt;Loop&lt;/span&gt;    
&lt;/pre&gt;&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;As I am not sure that you are changing the frequency to get the output you require - are you essentially doing this?&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;#&lt;span class="nv"&gt;chip&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="nv"&gt;F74&lt;/span&gt;
#&lt;span class="nv"&gt;option&lt;/span&gt; &lt;span class="nv"&gt;Explicit&lt;/span&gt;

&lt;span class="nv"&gt;HPWM&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;,&lt;span class="mi"&gt;20&lt;/span&gt;,&lt;span class="mi"&gt;128&lt;/span&gt;

&lt;span class="nv"&gt;Dim&lt;/span&gt; &lt;span class="nv"&gt;FrequencyRange&lt;/span&gt; &lt;span class="nv"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;Byte&lt;/span&gt;

&lt;span class="k"&gt;Do&lt;/span&gt;
    &lt;span class="k"&gt;For&lt;/span&gt; &lt;span class="nv"&gt;FrequencyRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
      &lt;span class="nv"&gt;HPWM&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;,&lt;span class="nv"&gt;FrequencyRange&lt;/span&gt;, &lt;span class="mi"&gt;128&lt;/span&gt;
    &lt;span class="k"&gt;Next&lt;/span&gt;
&lt;span class="k"&gt;Loop&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anobium</dc:creator><pubDate>Mon, 24 Aug 2020 08:12:46 -0000</pubDate><guid>https://sourceforge.net094d54a7ae9b2fe8f78ee3d9f4b72b1aa5e77df9</guid></item><item><title>Time for HPWM to Execute...420uS Sound Right?</title><link>https://sourceforge.net/p/gcbasic/discussion/579125/thread/bca5da90f2/?limit=25#5138</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Hi there. I'm doing a motor control project using the 16F74 to simulate an AC waveform. The waveform generation is working. It uses a table of sine values and uses the HPWM capability of the PIC to generate a pwm waveform which simulates a sine wave. At the moment it's generating into a r-c filter to filter the pwm and smooth the energy into a sine wave. The sine wave is split into 18 20degree segments, each segment is about 922us long.&lt;/p&gt;
&lt;p&gt;The issue I'm having is that my 60hz waveform is coming out at about 35hz lol. I have tracked the issue to the execution time of the HPWM. I created a small program which has some of the elements of the program in it to see what the delay is. Without the 'HPWM 1,20,128' test code, the main segment of the program runs in 28us. With the HPWM in, it increases to 448us. This has the tendancy to extend my segment thus making the sine wave slower (Lower F). Is there a way to reduce this time?&lt;/p&gt;
&lt;p&gt;Thanks all,&lt;/p&gt;
&lt;p&gt;Chay Foss&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chay Foss</dc:creator><pubDate>Mon, 24 Aug 2020 01:59:13 -0000</pubDate><guid>https://sourceforge.nete240dd7dd0e31ea10fa80dbb71c1770b2b6843db</guid></item></channel></rss>