K8055 Open Source Project

garbage == the code lines with incorrect checksum?

dear MostlyHarmless
PWM Frequency of pic18 is fixed? the same as original?

the schematics from viewtopic.php?f=3&t=4738&p=21339 used (pin4, Q6{or Q5 from datasheet}, divider 64)
seems that frequency of PWM is about 2915MHz (using divider about 45,5Hz measured). Can this be true?

garbage == the code lines with incorrect checksum?[/quote]

I think that the means that the processor will ignore invalid opcodes and simply move on to the next address. On some processors an invalid opcode will cause an exception.

garbage == the code lines with incorrect checksum?[/quote]

There are no checksums in the actual binary code. Checksums are only in the hex file for the boot loader or programmer, but they are not part of the bytes actually stored in the PIC’s program area.

[quote=“k750”]dear MostlyHarmless
PWM Frequency of pic18 is fixed? the same as original?

the schematics from viewtopic.php?f=3&t=4738&p=21339 used (pin4, Q6{or Q5 from datasheet}, divider 64)
seems that frequency of PWM is about 2915MHz (using divider about 45,5Hz measured). Can this be true?[/quote]
I am not exactly sure what the current PWM frequency really is. I think I just used the settings in J_Holland’s first firmware for the 18F.

If you need other PWM frequencies, how would you suggest making them variable and user controlled?

This is a “community” open source project. You are part of the “community”. You can make any changes you want and contribute them back to be incorporated into the master branch.

I set it up to be as close as possible to the original Velleman PWM frequency which is quoted in their spec. at around 25kHz, I can’t remember the exact number.

strange… using divider 2, measured 1465,2+0,1Hz (time - 20s). The frequency is ~2930,5Hz, seems fixed, but far away from 23,43kHz…
in near future will try measure using scope (don’t have this usefull thing) or other device.

at the moment, important was fixed frequency, near 2kHz.

sorry, but i don’t have enought knowledges… firmware patch with address was simple, and if user need only one but other fixed frequency, can compile the firmware with changed pwm freq. if some other frequencies needed and changing “on the fly”, than firmware+dll function(s)…

I’ll have to check that. One thing to note is that on my board I did have a different frequency crystal, it was just one that I had lying around.

I guess I really want a pocket oscilloscope for my birthday this year.

Hi,

I followed jannicash.info/k8055/ and burned my chip with the latest version of bootloader. I also made all the necessary hardware changes but can’t make bootloader working. When turned on with link on sk6 my computer doesn’t recognize HID device (LED1 stays always on). The board worked with the original Velleman firmware. I also tried to burn the chip with my routine just to check blinking LED and it worked. So the problem isn’t hardware. What then? I can’t find any solution.

The board sometimes works (I had it working 3 times out of hundreds of trials) and I can’t explain why. But still Microchip software after detecting the board went to timeout.

Any ideas?

PWM frequency, measured using AT7016 scope, is about 2941Hz…

K8055_PIC18F2550.h
is this for USB:
#define CLOCK_FREQ 48000000

after change to
#define K8055_T2CKPS0 1
#define K8055_T2CKPS1 0
because ww1.microchip.com/downloads/en/D … 39632e.pdf s.139
{bit 1-0 T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits
00 = Prescaler is 1
01 = Prescaler is 4
1x = Prescaler is 16}

i’m getting pwm freq about 11,7kHz

how to move up to ~23kHz?

pwm width - value:
100% - 244
0% -0

[quote=“k750”]K8055_PIC18F2550.h
is this for USB:
#define CLOCK_FREQ 48000000

after change to
#define K8055_T2CKPS0 1
#define K8055_T2CKPS1 0
because ww1.microchip.com/downloads/en/D … 39632e.pdf s.139
{bit 1-0 T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits
00 = Prescaler is 1
01 = Prescaler is 4
1x = Prescaler is 16}

i’m getting pwm freq about 11,7kHz

how to move up to ~23kHz?

pwm width - value:
100% - 244
0% -0[/quote]

Thank you for looking into this.

Yes, we know that the PWM frequency is currently off. I do have an oscilloscope on order and this is one of the things why I am buying one. According to the Microchip datasheet, the PWM period is [quote]PWM Period = [(PR2) + 1] • 4 • TOSC • (TMR2 Prescale Value)[/quote]

With PR2=255, Prescale=4 and TOSC=1/48000000 I calculate that the PWM frequency would currently be 11,719 Hz. Which is close enough to your measurement.

I think that PR2=127 should result in a PWM frequency of 23,438 Hz, which would be almost identical to the original K8055.

I will verify this as soon as I get my oscilloscope and change the code accordingly.

thank you for answer

i tried to change K8055_PWMPR2 to 125, but pwm frequency does not change (strange…).
This changes “scaling” of pwm bits - 100% are not 244, but ~111 (can’t remember exactly)
k8055m_firmware.c:
PR2 = K8055_PWMPR2;
seems, that this is the required PR2,… or the PR2 is at other place?

will verify “scaling” this evening again

[quote=“k750”]thank you for looking

i tried to change K8055_PWMPR2 to 125, but pwm frequency does not change (strange…).
This changes “scaling” of pwm bits - 100% are not 244, but ~111 (can’t remember exactly)
or the PR2 is at other place?[/quote]

That is indeed strange. Changing that parameter should change the PWM frequency. That it changes the scaling instead is very surprising. How exactly are you measuring the frequency and duty cycle of the PWM output?

And no, grep(1) cannot find any other places where PR2 is accessed at all. Just the assignment to PR2 during startup of the PIC, straight from the #define in the header.

As said, my oscilloscope is ordered and hopefully will get here around next weekend. Can’t wait to put that gadget through its first real world use case.

firmware with PR255 loaded, reset (from microchip bootloader tool), 74HC4024N connected

PR2 @ 255
have measured from falling edge to falling edge (1 period), 2 periods are ~8.5 division on scope screen
scope setting: 1division=20us
period=(8.5/2)*20=85us=0.000085s
freq=1/period=1/0.000085=11764.7Hz
pwm 50% @ ~114, 100% @ 250

PR2 @ 127
scope setting: 1division=20us
8,5*20us/4=42,5us
23529,4Hz (OK! sorry for false information in previous post :frowning: )
pwm 50% @ ~50, 100% @ ~121
mikroe.com/eng/chapters/view … p-modules/ : “In relation to this microcontroller, the resolution is specified by the PR2 register. The maximal value is obtained by writing number FFh”. This for PIC16F887.
In our case PWM, when PR2 set to something lower then FFh (255) /but more than 7Fh (127)/, seems to have only 7(+2?) bit resolution…
ww1.microchip.com/downloads/en/D … 39632e.pdf , s149.
But equation 15-3: for Fosc=48000kHz and Fpwm=23,529 gives 10.99bit (base of log = e)
the 18F2550 pwm is up to 10bit, s.148
where is the true?


Image above - duty about 25%

In this case duty of 100% @ only 121 (and up) pwm setting - at image below:

the modded k8055 has been reset from bootloader tool (no power cycle) and by power cycling - no diference

duty=(on_time/period)*100%
on_time=time between falling edge and rising edge (say at the middle of wave height) - k8055 “on” is low.
period=time between rising edge and second rising edge=time between falling edge and second falling edge

duty 0% - solid upper line, duty 100% - solid buttom line.

interesting site: micro-examples.com/public/mi … lator.html

i hope, its all correct. sorry for not the best quality images

Thank you very much, k750. That is excellent information.

Note that the K8055D.DLL compatibility layer converts the 8-bit analog-out value to 10-bits by <<2 making your 121 analog out value internally 484.

I think the coin just dropped. I had misunderstood how the 10-bit value in (CCPRXL:CCPXCON<5:4>) is used. It defines the duty cycle on_time in seconds and is calculated as

PWM Duty Cycle = (CCPRXL:CCPXCON<5:4>) • TOSC • (TMR2 Prescale Value)

So with PR2=127 our PWM period should be 42.7 uS resulting in 23.438 kHz and your measurement confirms that.
But with those settings the PWM Duty Cycle length at (CCPRXL:CCPXCON<5:4>) = 512 will also be 42.7 uS.

At any higher value than 512 (121 in your case of 8-bit compatibility and PR2=125), the duty cycle length will be greater than 42.7 uS and it basically stays at 100%. That means that we only have 512 distinct PWM settings and that equals 9 bits effective resolution. If using PR2=127, the compatibility layer therefore should only <<1 to retain the original 256 distinct settings (client/k8055d.c lines 201…212).

Unfortunately, the lowest possible PWM frequency at Timer2 prescaler=1 would be 46.875 kHz. We would need to have PR2=511 to get down to 23.43 kHz, which is not possible. So the smallest prescaler we can use to operate at 23.43 kHz is 4 and that limits us to 9 bits. At FOSC=48000000 we simply cannot have 23.43 kHz and 10 bit resolution. We can get 10 bits at either half or double the PWM frequency, but not at 23.43 kHz.

What we could do is to actually expose the PWM configuration settings (prescaler and PR2) to new commands in the k8055m library code and HID protocol. Then its up to the user.

Thanks again. Now it all makes sense!

thank you for deep explanation

the birthday is comming up? :wink:
it is (would be) pocket scope? what model?

[quote=“k750”]the birthday is comming up? :wink:
it is (would be) pocket scope? what model?[/quote]

I ordered a DSO203. Even considering it’s analog attenuation problems above 2 MHz, if the rest works as people on the forum indicate, it should make a good hobby O-scope and almost overkill for everything I do.

looks nice, congratulations to comming up birthday :smiley: