Hi
I am not able to get the resolution of 16bits, Could you just claify.
HPWM16On ( 3, 100, offsetFWD)
Offset forward being a word up to 65535, surely any value up to this would give a varied output.
I would like to use the output as a DC source, thru a 10kohm with a 10uF cap. I am only seeing resolution of around 1000.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#chip 12F1572,32
#config MCLR=ON
#option explicit
' GCB v98.04
dim offsetFWD as word
Dir PORTA.2 Out
dir porta.4 in
dir porta.5 in
offsetFWD = 45000
HPWM16On ( 3, 100, offsetFWD)
do Forever
if porta.5=false then
offsetFWD=offsetFWD+1
if OffsetFWD>65500 Then
offsetFWD=65500
end if
HPWM16(3, 100, offsetFWD)
Wait 100 mS
end if
if porta.4=false then
offsetFWD=offsetFWD-1
if OffsetFWD<200 Then
offsetFWD=200
end if
HPWM16(3, 100, offsetFWD)
Wait 100 ms
end if
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
porta.0 = 1
do Forever
dim PMWValue, _value as long
for PMWValue = 1 to 65536 step 64
HPWM16(3, 100, PMWValue )
wait 10 ms
next
porta.0 =!porta.0
wait 20 ms
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I adapted your code to get it respond a lot faster.
Pressing the button changes the duty cycle - starting at 65%
A slower frequency as a temp fix seems to work.
#chip 12F1572,16
#config MCLR=ON
#option explicit
' GCB v98.04
dim offsetFWD as word
Dir PORTA.2 Out
dir porta.4 in
dir porta.5 in
offsetFWD = 45000
HPWM16On ( 3, 100, offsetFWD)
do Forever
if porta.5=false then
offsetFWD=offsetFWD+100
if OffsetFWD>65500 Then
offsetFWD=65500
end if
HPWM16(3, 100, offsetFWD)
Wait 100 mS
end if
if porta.4=false then
offsetFWD=offsetFWD-100
if OffsetFWD<200 Then
offsetFWD=200
end if
HPWM16(3, 100, offsetFWD)
Wait 100 ms
end if
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if you check the datasheet for capabilities of the 16 bit PMW, I will check the code for updating the register.
But, I am not sure that you will see the change per step on a DMM as you change the duty. But, I will check how the register is bwing set per step change.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I played with the 12f1571 once upon a time, by manually manipulating the registers. I had it set up as an 8 bit PWM . I think all that would be required is to set the period register to PWM1PRH = 255 to make it a 16 bit. You could try it with different clock values, and see what you get?
The code might be something like this, not tested:
EDIT: whoops should use the load function to load buffers at the end of period.`
#chip 12f1572, 4
#define RedLed PortA.1
dim Red_PWM as Word Alias PWM1DCH, PWM1DCL
dim ramp as word
Call init_PWM
Do
For ramp = 0 to 65535
Red_PWM = ramp
PWM1LDCON.LDA = 1
wait 3 s
next
Loop
Sub Init_PWM
'---- Red PWM1 ----
dir PORTA.1 in
PWM1PRH = 255
PWM1PRL = 255
PWM1CON = b'11010000' 'enable pwm and set POL bit for common anode
PWM1CLKCON = b'00000000' '15.63kHz with PRL=255 4Mhz clk
PWM1PHH = 0
PWM1PHL = 0
PWM1DCH = 0
PWM1DCL = 0
PWM1LDCON.LDA = 1 'loads OFx, PHx, DCx, PRx buffers at end of period
dir PortA.1 out
Last edit: kent_twt4 2019-01-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Resolved. Dry joint
Hi
Not getting any output on pin 5 ( PWM3). Pin 6 is cycling correctly.
;Chip Settings
chip 12F1572,32
config MCLR=ON
' GCB v98.04
Dir PORTA Out
#define HPWM16_3_Freq 100
#define HPWM16_3_Duty 50
HPWM16On ( 3 )
do Forever
set porta.1 on
wait 1 s
set porta.1 off
wait 1 s
loop
```
Last edit: Anobium 2019-01-10
Sorry , but your code works here. I am getting a 100khz signal on Ra.2/pmw3
Check your config/chip.
Anobium
Sorry. Appologies, found a dry joint on board.
Hi
I am not able to get the resolution of 16bits, Could you just claify.
HPWM16On ( 3, 100, offsetFWD)
Offset forward being a word up to 65535, surely any value up to this would give a varied output.
I would like to use the output as a DC source, thru a 10kohm with a 10uF cap. I am only seeing resolution of around 1000.
Please representive code. I can only guess what the code is.
Is offsetFWD a word? a byte?
Are you using #option explicit?
Keep the code short but representative.
Cheers
Looks like a small issue with PWM16.
Please use a lower frequency, or, hand carft the regsisters.
My tests.
All the static code looks good, but, we he is passing variable at specific frequencies then I think things are not perfect.
My test code - this works. I get 10% but when I change the chip frequency 32mhz things are not correct.
***** Second program
This shows the issue. Works at 16 and not at 32. There may be an overflow issue somewhere.
' HPWM16(1, 10, 16384) '10 kHz, 25% duty cycle (16384/65535)
' HPWM16(2, 20, 16384) '20 kHz, 25% duty cycle (16384/65535)
HPWM16(3, 30, 16384) '30 kHz, 25% duty cycle (16384/65535)
I adapted your code to get it respond a lot faster.
Pressing the button changes the duty cycle - starting at 65%
A slower frequency as a temp fix seems to work.
I was hoping to use full resolution of '1' increment/decrement.
Looks to that you can. But, at the moment at slower chip frequency.
Are you saying you cannot?
Even by changing to a lower frequency i am not getting the resolution. Looks as though resolution is set at 10bit.
OK. When Pete has a look then he can look into that also.
Do you have any code that proes this? Like code that compares the 16bit registers and outputs to a serial terminal?
I do not have more code. I am using a 6 1/2 digit DMM. Therefore 5V/65535=76.3uV
I am not seeing this change when incrementing/decrementing by 1.
if you check the datasheet for capabilities of the 16 bit PMW, I will check the code for updating the register.
But, I am not sure that you will see the change per step on a DMM as you change the duty. But, I will check how the register is bwing set per step change.
I played with the 12f1571 once upon a time, by manually manipulating the registers. I had it set up as an 8 bit PWM . I think all that would be required is to set the period register to PWM1PRH = 255 to make it a 16 bit. You could try it with different clock values, and see what you get?
The code might be something like this, not tested:
EDIT: whoops should use the load function to load buffers at the end of period.`
Last edit: kent_twt4 2019-01-11