P8055n-2 possible software errors

I have just completed the P8055N-2 board.
The build was well documented and went without issue.
On balance an excellent product.

The downloaded dll reports it is version 5.0.0.0

During testing I have discovered a couple of dll issues.

  1. pwm1 and pwm2 outputs will only set to a frequency of 46.9Khz.

I am using the following call to
Private Declare Sub SetPWM Lib “k8055d.dll” (ByVal channel As Integer, Data As Integer, frequency As Integer)

I am expecting that the frequency can be set using an integer value 1,2 or 3:
1 (2929.68Hz)
2 (11718.75 Hz)
3 (46875Hz)

setpwm(1,128, frequency)
It does not matter if frequency is set to 1,2,3 or any other value, the pwm lines produce 46.9 Khz

  1. pwm1 can be disabled correctly using a call to either of these:
    Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal channel As Long)
    Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()

However if pwm2 has been activated a call to either clear analogue routines results in pwm2 clearing and out1 setting (With led on)

This fault does not appear if DAC2 is set and then cleared.

Has anyone else experienced this?

The analogue inputs are perhaps not as stable as I would hope.
There appears to be a ± 0.1 V drift
Has anyone experienced this?
I wonder if there is a fluctuating reference voltage in the circuit?

David

[quote=“drp”]I have just completed the P8055N-2 board.
Th build was well documented and went without issue.
On balance an excellent product.[/quote]
Welcome to the forum and I agree, these cards are well made.

Note that I don’t use the actual DLL, but a Python module on FreeBSD that uses the same HID commands.

[quote=“drp”]During testing I have discovered a couple of dll issues.

  1. pwm1 and pwm2 outputs will only set to a frequency of 46.9Khz.

I am using the following call to
Private Declare Sub SetPWM Lib “k8055d.dll” (ByVal channel As Integer, Data As Integer, frequency As Integer)

I am expecting that the frequency can be set using an integer value 1,2 or 3:
1 (2929.68Hz)
2 (11718.75 Hz)
3 (46875Hz)

setpwm(1,128, frequency)
It does not matter if frequency is set to 1,2,3 or any other value, the pwm lines produce 46.9 Khz[/quote]
This does not happen in my testing. Using HID command tag 23 and the appropriate other bytes according to the Pascal code of the K8055D.DLL, I can change the PWM frequency as expected. However, that PWM frequency code is only honored when setting channel 1 and is apparently ignored when setting channel 2.

[quote=“drp”]2) pwm1 can be disabled correctly using a call to either of these:
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal channel As Long)
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()

However if pwm2 has been activated a call to either clear analogue routines results in pwm2 clearing and out1 setting (With led on)[/quote]
I can reproduce this problem. To be more precise, this happens when SetPWM() was last used to set channel 2 and then one of the SetAnalog or ClearAnalog functions is used.

The bad news is that this seems to be a problem inside the firmware. I cannot see any bug in either the official Pascal library code or my Python code.

The workaround for this seems to be that if you used SetPwm(port, value, frequency) to activate the port, then turn it off with SetPwm(port, 0, 3).

The PWM and DAC ports are the exact same pin on the PIC. The DAC port just has a slewing capacitor and an OP-AMP to make it appear as if there was an analog signal. The SetAnalog functions use different HID command tags so the PWM frequency stays at the default.

[quote=“drp”]The analogue inputs are perhaps not as stable as I would hope.
There appears to be a ± 0.1 V drift
Has anyone experienced this?
I wonder if there is a fluctuating reference voltage in the circuit?[/quote]

Yes, I have experienced that. And this is more pronounced on my K8055N than on the older K8055. I am not 100% sure what causes it. However, these are possible reasons.

The cards don’t really use a separate, stable “reference” voltage for ADC. They use a PIC internal one that is derived from the supply voltage. That supply voltage is the USB 5V supply on the K8055 and 3.3V regulated with a LM317 on the K8055N. Since it powers a number of components on each board, it is naturally subject to noise, which lets the measurement results bounce around somewhat.

For the K8055N, depending on the ambient temperature and the current drawn by the board, the LM317 drop-out voltage can be really close to the 1.7V available. With changing temperature, your card may be going into and out of that drop-out condition.

Regards,
Jan

Thanks for those observations Jan,

I am using vb6 and can not get either channel 1 or 2 to apply the settings.
Both the frequency and duty cycle remain unchanged.

I presume your output port 1 goes high?

Your work round did not work at all for me- the pwm2 port continues to output.
This is hardly surprising because the frequency is not being recognised in the dll call.

Can you post your working version of the dll call?
I am using:
Private Declare Sub SetPWM Lib “k8055d.dll” (ByVal channel As Integer, Data As Integer, frequency As Integer)
(I wonder about the integer type?)

A little disappointing.

Cheers,
David

[quote=“drp”]I am using vb6 and can not get either channel 1 or 2 to apply the settings.
Both the frequency and duty cycle remain unchanged.[/quote]
As said, I am using equivalent Python code. My code doesn’t use the DLL but the Python ctypes module and on Unix systems also the pylibusb module.

I just translate what my code does to how one would do it using the K8055D.DLL.

That should however make no difference because AFAICT the HID packets sent/received are the exact same. At least as far as it matters for this problem.

Correct. The sequence

SetPWM(2, something, something) ClearAllAnalog()
does turn digital output 1 on.

However, on further investigation I was wrong. This is not inside the firmware, this is in the DLL. The function SetPWM() overloads the digital output field in the HID command with the channel number minus 1 to send the SetPWM() command to the card. That byte is not saved/restored during the call, so if the next command is not SetAllDigital(), then all the digital port settings get messed up. Since it also overloads the fields for both analog channels, similar side effects should be expected when using a mix of SetPWM() and SetAnalogChannel().

Try this sequence to see what I mean:

SetAllDigital() SetPWM(0, 127, 3) // sleep a second or two; all digital channels are on now ClearAllAnalog()
All digital outputs off now. Look at that … I even ported that bug into my Python code … LOL.

You can expect DLL version 5.0.0.3 soon. Velleman staff is paying very close attention to this forum and reacts very fast to this sort of feedback.

[quote]Your work round did not work at all for me- the pwm2 port continues to output.
This is hardly surprising because the frequency is not being recognised in the dll call.

Can you post your working version of the dll call?
I am using:
Private Declare Sub SetPWM Lib “k8055d.dll” (ByVal channel As Integer, Data As Integer, frequency As Integer)
(I wonder about the integer type?)[/quote]
Nope, I don’t even have any Basic compiler on any of my computers. Here most things are done on FreeBSD or Linux. That said, the declaration looks fine to me.

Regards,
Jan

Hi Jan,
I have fiddled with the vb6 dll declaration
This works up to a point:
Private Declare Sub SetPWM Lib “k8055d.dll” (ByVal channel As Integer, ByVal Data As Integer, ByVal frequency As Integer)

With PWM1 (channel 1) I can set the mark space ratio with Data and alter the frequency.
With PWM2 (channel 2) I can change the ratio but the frequency stays at 46.9Khz, regardless.

Call using:
SetPWM 1, 128, 1
or…
dim mychannel , mydata, myfrequency as integer
mychannel = 1
mydata = 128
myfrequency = 1
SetPWM mychannel, mydata, myfrequency

Regards,
David

David,

[quote=“drp”]With PWM1 (channel 1) I can set the mark space ratio with Data and alter the frequency.
With PWM2 (channel 2) I can change the ratio but the frequency stays at 46.9Khz, regardless.[/quote]
Yes, apparently the frequency is only set when calling SetPwm for channel 1. But if you do

SetPwm(1, 63, 1) SetPwm(2, 191, ignored)
then both channels will operate at 2.9 kHz. Channel 1 at 25% duty cycle, channel 2 at 75% duty cycle.

This is a limitation of the PIC itself. The PWM frequency in PIC18 devices is controlled by timer module 2 for all PWM output channels. Specifically by the value of register “PR2” and the “TMR2 Prescaler Value”. Only the duty cycle (mark space ratio) is individual per channel.

The PIC itself can generate many more frequencies with still reasonable duty cycle precision. It is explained in detail in chapter 15.4 of the PIC18* data sheets.

The thing controlled with the “frequency” parameter of SetPwm() is only the “TMR2 Prescaler Value”. That prescaler can only be set to 1, 4 or 16. Velleman has not made the PR2 register controllable. Doing so would cause significant backwards compatibility issues with the older K8055.

Regards,
Jan

Thank you drp and MostlyHarmless for the feedback.
Indeed, there was a bug in the undocumented DLL function SetPWM().
Now it should be fixed.
Here is the link to download the updated v5.0.0.3 of the K8055D.DLL with source:
app.box.com/s/9bsnqirw390miyc1n38o

[quote=“MostlyHarmless”]Yes, apparently the frequency is only set when calling SetPwm for channel 1. But if you doSetPwm(1, 63, 1) SetPwm(2, 191, ignored)
then both channels will operate at 2.9 kHz. Channel 1 at 25% duty cycle, channel 2 at 75% duty cycle.
This is a limitation of the PIC itself. The PWM frequency in PIC18 devices is controlled by timer module 2 for all PWM output channels. Specifically by the value of register “PR2” and the “TMR2 Prescaler Value”. Only the duty cycle (mark space ratio) is individual per channel.[/quote] This is good notification. The PWM frequency is equal for both channels. The parameter “frequency” is useless for channel 2.

drp: In Visual Basic 2008, the integer data types differ from those in Visual Basic 6.0.
In VB6 the 32-bit integer is defined “As Long” and in VB2008 “As Integer”.
So the SetPWM declration in VB6 should be:Private Declare Sub SetPWM Lib "k8055d.dll" (ByVal channel As Long, ByVal Data As Long, ByVal frequency As Long)
and in VB2008:Private Declare Sub SetPWM Lib "k8055d.dll" (ByVal channel As Integer, ByVal Data As Integer, ByVal frequency As Integer)

For more info:
“Integer Data Type for Visual Basic 6.0 Users”
“Parameter Passing Mechanism for Visual Basic 6.0 Users”
http://msdn.microsoft.com/en-us/library/7f5ztkz3(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/41zywfyc(v=vs.90).aspx

[size=85]Visual Basic 6.0
In Visual Basic 6.0, if you do not specify ByVal or ByRef for a procedure parameter, the passing mechanism defaults to ByRef. This allows the variable passed into the procedure to be modified in the calling program.

Visual Basic 2008
When you declare a procedure in Visual Basic 2008, the passing mechanism defaults to ByVal for every parameter. This protects arguments against modification.[/size]

Well done support!

I have tested the modified dll: (Version 5.0.0.2 reported but downloaded as 5.0.0.3)

  1. Output ports now remain as they were during the pwm1/2 reset- I checked ClearAllAnalog and ClearAnalogChannel
  2. Setting the frequency for pwm1 does set the frequency for pwm2.
  3. The duty cycle (mark space ratio) can be set independently. (CRO verified)
  4. The dll declaration:

In my vb6 the SetPWM function worked successfully with the dll declaration “…as long” and “…as integer”
“ByVal” is essential.
Variations in the capitalisation of “SetPWM” failed.

All I need now are some pointers for improving the Analogue to digital stability.

Thanks,
David

The reference voltage is quite stable 3.3V, but the test voltage via jumpers SK2 and SK3 is coming directly from the PC’s USB bus.
Have you tested also with external voltage e.g. 1.5V battery?
How big is the fluctuation in this case?

Normally there shouldn’t be any fluctuation.
The software K8055N_Demo.exe should displays stable and fixed results.

Hi,
I have tested the analogue to digital ports with an external battery source.
A1 fluctuates more rapidly than a2.
The variation is ± 1 on A2 and up to ±2 on A1.

±1 equates to 1*5/256 V … ±0.0195V (Approx 0.02V)

The effective input impedence of the converter circuit must be very low-
The output voltage of my potentiometer test circuit dropped 1.06 volts when I connected to A1.
I got a similar voltage drop for A2.

It looks like the converters have a maximum resolution of 1 bit in 255

Regards,
David

[quote]The effective input impedence of the converter circuit must be very low-
The output voltage of my potentiometer test circuit dropped 1.06 volts when I connected to A1.
I got a similar voltage drop for A2.[/quote]The input impedance of A1 and A2 analog inputs is 100k ohms.
Do you see similar fluctuation if you connect the 1.5V battery directly (without potentiometer) to the analog input?

[quote]It looks like the converters have a maximum resolution of 1 bit in 255[/quote]Yes, the converters are 8-bit.

Hi,
If the input impedance is only 100K, that helps to explain the fluctuations and the current drain on the applied voltage source. Particularly for high impedence sources!

I have tested with an external impedance 0f 0-100k.
At lower external impedences the analogue to digital converter is stable.
As it would be with a battery- but who regularly uses an a/d converter to measure a battery?
As the external impedence rises above 50K the instability grows.

It might be worth trying an op amp voltage follower between the source and the a/d input.

Cheers,
David

Done that … with NTCs all over this forum. Enjoy reading those threads.

Regards,
Jan

An update:

I have made a buffer box to connect to the K8055N / P8055N.
It consists of:

  1. 4mm sockets for all of the boards’ input, output, a/d and d/a connections.
  2. Rail to rail voltage follower op amp to increase the input impedence of the a/d ports.
  3. 1K resistors to tie the pwm outputs to the clamp and supply rail.
  4. A usb power lead with 400mA fuse.
  5. A 10 way ribbon cable with 2.54mm Pitch 10 Way IDC Cable Mounting Socket. This carries 0V ,5V and the ouput lines for additional board connectivity.

I made comb connector plugs for the buffer box to K8055N connection. With ribbon cable and shrink tubing.
For these I used 2.54 mm pin header strip, with every second pin removed.
The strip can be cut to the length of a section of the K8055n ports.
The shorter connector sections- groups of 3/4/5 can be made without any re-enforcement.
The output section does need the strip soldering to a bit of strip board.
The comb connectors can easily be inserted into a group of P8055N sockets and the grub screws tightened.

Cheers,
David