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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
dimADC_VALaswordHPWM3,2,[word]0,2'Maincode
I will add this to the Help if this works - this is casting issue that other should not have to discover.
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Simple fix, install this to your installation please https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/pwm.h
Here are the changes. https://sourceforge.net/p/gcbasic/code/651/
My install is unmodified "98.01"
I installed the new pwm.h from the link above. Now I get an odd error at complile.
Install the three files shown below:
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel.dat
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/pwm.h
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/pwm16.h
Install file #1 in the ..include folder and #2 & #3 in the ..include\lowlevel folder.
Last edit: Anobium 2017-11-07
Resolved. Please ensure you download the latest PWM.H
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.
Last edit: AndB 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.
or
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
Thanks that worked fine.
Not sure why I did not try that :)
See https://github.com/Anobium/Great-Cow-BASIC-Help/blob/master/source/HWpwmupdate.adoc
The Help was not updated when we fixed the initial issue... therefore, the example code was not helping. :-)
Is the updated Help ok?
Yep looks good.
I guess the sourceforge help version hasnt been updated yet.
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
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?
Snapshot is a snap shot of the current state of GitHub Help.
I just found this information. https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/search?utf8=%E2%9C%93&q=HPWMUpdate&type= select the file URL. Do the notes in this file match with your experience and findings?
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
[word]0
adding 1023 extra function
adding True extra function
True. If I did not document... what would you think. :-)
I would not know what to do :)
Thanks again for a great tool.
Pleasure.
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
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.
edited by Anobium to correct constant usage
LowSpeed
asSlow
Last edit: Anobium 2018-02-10
Can you use #define ADSpeed 0 ?
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 beenLowSpeed
. Sorry - this is probably the confusion. I have edited that post.Last edit: Anobium 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
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.
62.5ns to 2us using FSOC
1 to 6us using FRC