Use PWM Output at J4-15

      Hello,
      Where do i find more information to the driver for PWM output ?
      Please use Device Driver Document for FSVYBRID.
      You will it here fs-net.de/de/produkte/netdcu/netdcua5/ -> Documents.

      ... a file "pwm_sdh.h", this file was not fount on my System.
      Which SDK have you installed? I found it in FSVybrid WEC7 and FS Vybrid WEC2013 SDK. Thereby the content:

      C Source Code

      1. /*++
      2. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
      3. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
      4. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
      5. PARTICULAR PURPOSE.
      6. Copyright (c) 2008 F&S Elektronik Systeme GmbH
      7. Module Name:
      8. pwm_sdk.h
      9. Abstract:
      10. This module contains the constant, type and structure definitions for the
      11. NetDCU10-WINCE PWM Interface (ND10_PWM.DLL) device driver.
      12. Notes:
      13. --*/
      14. #ifndef __PWMSDK_H__
      15. #define __PWMSDK_H__
      16. #ifdef __cplusplus
      17. extern "C" {
      18. #endif
      19. // We'll need some defines
      20. #include "WINIOCTL.h"
      21. /* Entries in Registry */
      22. #define REG_VAL_FREQ TEXT("Freq")
      23. #define REG_VAL_STEPS TEXT("Steps")
      24. #define REG_VAL_MODE TEXT("Mode") /* 0=Absolute mode, write value between 0..(Steps-1) */
      25. /* 1=relative mode, write value between 0..100*/
      26. /* Default: 1 */
      27. #define REG_VAL_DEF TEXT("Default")
      28. #define REG_VAL_CHANNEL TEXT("Channel") /* 0=TOUT0, 1=TOUT1 */
      29. #define REG_VAL_DEBUG TEXT("Debug") /* Debug verbosity */
      30. // New IOControlCode values
      31. #define FILE_DEVICE_PWM 0x0000800B
      32. // IOCTL_PWM_REINIT:
      33. // Read registry and init digital I/O's
      34. // DeviceIoControl( hDIO, IOCTL_DIO_REINIT,
      35. // NULL, 0,
      36. // NULL, 0, NULL );
      37. #define IOCTL_PWM_REINIT CTL_CODE(FILE_DEVICE_PWM, 63, METHOD_BUFFERED, FILE_ANY_ACCESS)
      38. typedef struct tagPWM_INFO
      39. {
      40. WORD wVerMajor;
      41. WORD wVerMinor;
      42. WORD wSteps; /* Length of counter, read from reg value Steps */
      43. DWORD dwFreq;
      44. WORD wMode;
      45. WORD wFree1;
      46. DWORD dwTemp[14];
      47. } PWM_INFO;
      48. // IOCTL_PWM_GETINFO:
      49. // Read registry and init digital I/O's
      50. // PWM_INFO cInfo;
      51. // DeviceIoControl( hPWM, IOCTL_PWM_GETINFO,
      52. // NULL, 0,
      53. // &cInfo, sizeof(PWM_INFO), NULL );
      54. #define IOCTL_PWM_GETINFO CTL_CODE(FILE_DEVICE_PWM, 64, METHOD_BUFFERED, FILE_ANY_ACCESS)
      55. #ifdef __cplusplus
      56. }
      57. #endif
      58. #endif/*__PWMSDK_H__*/

      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Post was edited 2 times, last by “fs-support_ZU” ().

      Hello,

      the SDK is Win CE 60 for NETDCUA5 with Visual Studio 2008

      please give me a sample to use the driver, like this:

      // open File handler
      hPWM = CreateFile(_T("PWM1:"), .................................);

      // write to set pwm output parameter
      WriteFile(hPWM, ...........................);


      is this file pwm_sdk.h ok to include to my project with win ce60 ?

      Thanks
      Thomas
      Hello,

      the code is independend from the OS in use. Do you really need support for calling OS functions;). If registry value "Mode" is configured as "percent mode" following results a PWM with 40% high phase:

      Source Code

      1. // Open the port.
      2. hPWM = CreateFile(_T(PWM1:), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      3. /*TODO: Errorhandling*/
      4. // Write data
      5. WORD wData = 40;
      6. DWORD dwData = sizeof(WORD);
      7. WriteFile(hPWM, &wData, dwData, &dwWritten, NULL);
      8. /*TODO: Errorhandling*/
      9. ---
      10. CloseHandle(hPWM)

      Note, by default PWM is deactivated (registry value Flags=4). Please delete this value to activate the driver.
      Any problems? Which values return "GetLstError()"? Which Information si shown on the serial debug line (driver loaded)?
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hello,

      thanks for the sample, it works.

      I need a tunable PWM Frequency from 50-70Hz, but the registry setting for PWM frequency lower than 1260 has no effect.
      The lowest Frequency is always 1260Hz.

      Is it possibility to set the PWM frequency in the range between 50-70Hz ?

      Thanks
      Thomas
      Hello,

      i checked out:
      at the time PWM driver uses Vybrids Flex Timer Module and IPS Clock as source clock. This results in a minimal frequency of 1259.3Hz (=1260Hz)!
      For go below this limt a driver modification is needed.

      Any deadlines? At the time we are busy.
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hello,

      there's no hurry,
      but it's important to tune the frequency with my application without reset windows.
      The best solution are, when i can set the output frequency in 1Hz steps from 45 to 100Hz.
      At this moment it is importent to know is it possible to modyfy the driver with this function ?

      Otherwise i must generate the signal with external Hardware.
      In the next Days i must finalize the hardware. For the Software they are another 4 weeks.

      kind regards
      Thomas
      Hello, attached you will find the pwm driver V1.5 for WCE6/WCE7.
      I test according the code below (unforunately under WEC2013 but this should be not significant). Does this driver fulfills your desire?

      Source Code

      1. int wmain(int argc, wchar_t *argv[])
      2. {
      3. const int DTS = 3;
      4. BYTE myDT[DTS] = {10,50,90};
      5. const int FREQS = 7;
      6. DWORD myFreq[FREQS] = {40,100,400,1000,4000,10000,40000};
      7. unsigned long written;
      8. int j=0;
      9. HANDLE hPWM = CreateFile(_T("PWM1:"),GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      10. do
      11. {
      12. HKEY hKey;
      13. LONG res = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("Drivers\\Builtin\\NetDCUA5\\PWM"), 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
      14. if(res != ERROR_SUCCESS)
      15. {
      16. RETAILMSG(1,(L"Open HKLM\\Drivers\\Builtin\NetDCUA5\PWM, error %d\r\n", GetLastError()));
      17. }
      18. else
      19. {
      20. RegSetValueEx(hKey, _T("Freq"), 0, REG_DWORD,(BYTE * const)(&myFreq[j]), sizeof(DWORD));
      21. j++;
      22. j=j%FREQS;
      23. RegCloseKey(hKey);
      24. DeviceIoControl(hPWM, IOCTL_PWM_REINIT, NULL, 0, NULL, 0, NULL, NULL );
      25. }
      26. for(int i = 0; i < DTS; i++)
      27. {
      28. if(!WriteFile(hPWM, &myDT[i], sizeof(BYTE), &written, NULL))
      29. RETAILMSG(1,(L"WriteFile failed, error %d\r\n", GetLastError()));
      30. if(written != 1)
      31. RETAILMSG(1,(L"Bytes written != 1, error %d\r\n", GetLastError()));
      32. /*TODO
      33. PWM_INFO cInfo;
      34. DeviceIoControl(hPWM, IOCTL_PWM_GETINFO, NULL, 0, &cInfo, sizeof(PWM_INFO), NULL, NULL );
      35. */
      36. Sleep(5000);
      37. }
      38. }while(true);
      39. CloseHandle(hPWM);
      40. }

      Files
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hello,
      nice that everything is working fine now. If any further issue about pwm features please come back to this thread.
      Thank you too for your patience.
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.