Menu

"HPWMUpdate" does not seem to work as expected

Help
2017-11-06
2018-02-10
  • William Roth

    William Roth - 2017-11-06

    CHIP: PIC16F1769
    GCB Compiler: 0.98.01

    When using "HPWMUPDATE" the duty cycle is not correctly updated. The duty out jumps/changes in large steps given a relativel small setting change .

    Updating the duty cycle in the traditional manner seems OK.

    Source and ASM are attached.

    Please tell me what I am doing wrong. This is my first attempt at using "hpwmupdate"

    Bill

     

    Last edit: William Roth 2017-11-06
  • William Roth

    William Roth - 2017-11-07

    My install is unmodified "98.01"

    I installed the new pwm.h from the link above. Now I get an odd error at complile.

     Aborting due to runtime error 7 (null pointer access) at line 1959 of     D:\code\GCBASIC\trunk\preprocessor.bi::RUNSCRIPTS()
    
     6.3  Sec.    <<<   WARNINGs / ERRORs while compiling!
    
     
  • AndB

    AndB - 2018-02-08

    I'm having problems using HPWMUpdate .
    It's outputing an 8 bit PWM and not 10bit.
    I have latest Great cow basic installed.

    I've tried all files above as well.

    'Select chip model and speed
    #chip 16F1705, 32
    
    'Generated by PIC PPS Tool for Great Cow Basic
    '
    'Template comment at the start of the config file
    '
    #startup InitPPS, 85
    
      Sub InitPPS
    
             'Module: PWM3
             RA2PPS = 0x000E    'PWM3OUT > RA2
    
      End Sub
        'Template comment at the end of the config file
    
    
    
    #define USE_AD2 FALSE
    #define USE_AD2 FALSE
    #define USE_AD3 FALSE
    #define USE_AD4 FALSE
    #define USE_AD5 FALSE
    #define USE_AD6 FALSE
    #define USE_AD7 FALSE
    #define LED PORTA.2
    
    Dir PORTA.0 In
    Dir PORTA.1 In
    Dir PORTA.2 Out
    'SET ADPREF1 OFF
    'SET ADPREF0 On
    'Set ADNREF Off
    
    dim ADC_VAL as word
    HPWM 3, 2,0, 2
    'Main code
    
    do
    ADC_VAL = ReadAD10( AN0, true )
         HPWMUpdate 3,ADC_VAL
    loop
    
     

    Last edit: AndB 2018-02-09
  • Anobium

    Anobium - 2018-02-09

    Use the following to ensure the ADC_VAL is a WORD. Passing a zero is being treated as a byte [range of 0 to 255] and then when you pass ADC_VAL [range 0 to 1023] then stored reference values are not correct.

    To resolve.

    dim ADC_VAL as word
    ADC_VAL = 0
    HPWM 3, 2,ADC_VAL, 2
    'Main code
    

    or

    dim ADC_VAL as word
    HPWM 3, 2,[word]0, 2
    'Main code
    

    I will add this to the Help if this works - this is casting issue that other should not have to discover.

    Anobium

    My test code is attached.

     

    Last edit: Anobium 2018-02-09
  • AndB

    AndB - 2018-02-09

    Thanks that worked fine.
    Not sure why I did not try that :)

     
  • AndB

    AndB - 2018-02-09

    Yep looks good.

    I guess the sourceforge help version hasnt been updated yet.

     
    • Anobium

      Anobium - 2018-02-09

      It takes a day to update SourceForge. The process runs at 1200 London time. Take a snap-shot of GitHub, processes.. lots of magic... and then SourceForge is updated. :-)

      Good to sort this one out - it confused me. I looked at the ASM then the answer jumped out at me. :-)

       

      Last edit: Anobium 2018-02-09
  • AndB

    AndB - 2018-02-09

    Well done for spotting it and thanks for helping out so quickly.

    Snap shot? you'll have to explain as I'm not familiar with is.

    Is it Mac only?

     
  • AndB

    AndB - 2018-02-09

    Looks OK.

    One thing that niggles me is that you now have four ways to set the word.
    Flexabilty is great :)

    setting a variable word

    dim ADC_VAL as word
    ADC_VAL = 0
    HPWM 3, 2,ADC_VAL, 2
    

    [word]0

    HPWM 3, 2,[word]0, 2
    

    adding 1023 extra function

    HPWM 3, 2,0, 2,1023
    

    adding True extra function

    HPWM 3, 2,0, 2,True
    
     
    • Anobium

      Anobium - 2018-02-09

      True. If I did not document... what would you think. :-)

       
  • AndB

    AndB - 2018-02-09

    I would not know what to do :)

    Thanks again for a great tool.

     
    • Anobium

      Anobium - 2018-02-09

      Pleasure.

       
  • AndB

    AndB - 2018-02-09

    Just testing out the ad to pwm and it seems to jitter in sections as the AD voltage changes.
    A for next routine 0 to 1023 and back sweeping looks Ok with a small amount of jitter but the AD version is not quite right.
    Do you have any suggestions on what I can do to improve the conversion.
    Thanks

     
    • Anobium

      Anobium - 2018-02-09

      Interesting. No glitches here but here is the code. Check you 0v/ground plane - this is the place I would be looking.

      So, use ADSPEED - lots of other insights in the Help on the values.

      #define ADSpeed LowSpeed 
      
      do
           ADC_VAL = ReadAD10( AN0  )
           HPWMUpdate 3,ADC_VAL
      loop
      

      edited by Anobium to correct constant usage LowSpeed as Slow

       

      Last edit: Anobium 2018-02-10
  • AndB

    AndB - 2018-02-09

    Can you use #define ADSpeed 0 ?

     
  • Anobium

    Anobium - 2018-02-10

    No. You should use the defined constants.. The underlying libraries expect the define constants (LowSpeed etc) therefore if it was implied that a constant value that was not the define constant values the library will fail to operate as expected.

    Note: I used, totally incorrectly used a constant called slow where the constant should have been LowSpeed. Sorry - this is probably the confusion. I have edited that post.

     

    Last edit: Anobium 2018-02-10
  • AndB

    AndB - 2018-02-10

    All connections are soldered .
    GND/Supply is good.
    Analogue signal is also stable.

    I've found that ADSpeed does not accept HighSpeed?
    Stops working.
    I had added the Defines as thought it may be these missing in the prog.
    Still does not work on HighSpeed.

    Using Lowspeed has reduced the jitter a touch.
    I have had to add a trim IF then routine to stop the jitter and it needed the negative side adjusted by two digits.

    If there is anything else I can do without adding the if then to dampen the jitter please let me know.

    thanks

    'Select chip model and speed
    #chip 16F1705, 32
    
    'Generated by PIC PPS Tool for Great Cow Basic
    '
    'Template comment at the start of the config file
    '
    #startup InitPPS, 85
    
      Sub InitPPS
    
             'Module: PWM3
             RA2PPS = 0x000E    'PWM3OUT > RA2
    
      End Sub
        'Template comment at the end of the config file
    
    
    
    #define USE_AD2 FALSE
    #define USE_AD2 FALSE
    #define USE_AD3 FALSE
    #define USE_AD4 FALSE
    #define USE_AD5 FALSE
    #define USE_AD6 FALSE
    #define USE_AD7 FALSE
    #define HighSpeed 255
    #define MediumSpeed 128
    #define LowSpeed 0
    #define ADSpeed LowSpeed
    
    
    Dir PORTA.0 In
    Dir PORTA.1 In
    Dir PORTA.2 Out
    SET ADPREF1 OFF
    SET ADPREF0 OFF
    Set ADNREF Off
    
    dim ADC_VAL as word
    dim ADC_VAL_OLD as word
    ADC_VAL = ReadAD10( AN0, true )
    ADC_VAL_OLD = ADC_VAL
    
    'Main code
    
    do
    ADC_VAL = ReadAD10( AN0, true )
    if ADC_VAL > ADC_VAL_OLD or ADC_VAL < ADC_VAL_OLD - 1 then
    HPWM 3, 2, ADC_VAL, 2
    ADC_VAL_OLD = ADC_VAL
    end if
    loop
    
     
  • Anobium

    Anobium - 2018-02-10

    This may be caused by the minimum time between ADC reads. Can you check the datasheet for this period. But, the faster the chip frequency then you will need to use the slower constants.

     
  • AndB

    AndB - 2018-02-10

    62.5ns to 2us using FSOC
    1 to 6us using FRC

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.