{"action":"created","issue":{"url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/2","repository_url":"https://api.github.com/repos/per1234/PalatisSoftPWM","labels_url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/2/comments","events_url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/2/events","html_url":"https://github.com/per1234/PalatisSoftPWM/issues/2","id":139235685,"number":2,"title":"Support >256 PWM levels","user":{"login":"per1234","id":8572152,"avatar_url":"https://avatars.githubusercontent.com/u/8572152?v=3","gravatar_id":"","url":"https://api.github.com/users/per1234","html_url":"https://github.com/per1234","followers_url":"https://api.github.com/users/per1234/followers","following_url":"https://api.github.com/users/per1234/following{/other_user}","gists_url":"https://api.github.com/users/per1234/gists{/gist_id}","starred_url":"https://api.github.com/users/per1234/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/per1234/subscriptions","organizations_url":"https://api.github.com/users/per1234/orgs","repos_url":"https://api.github.com/users/per1234/repos","events_url":"https://api.github.com/users/per1234/events{/privacy}","received_events_url":"https://api.github.com/users/per1234/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/per1234/PalatisSoftPWM/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/per1234/PalatisSoftPWM/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-08T10:16:22Z","updated_at":"2016-03-24T09:04:06Z","closed_at":null,"body":"When using this library with LEDs there is a large difference between PWM levels at low brightness so the option of more PWM levels than 256 would be useful."},"comment":{"url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/comments/200746283","html_url":"https://github.com/per1234/PalatisSoftPWM/issues/2#issuecomment-200746283","issue_url":"https://api.github.com/repos/per1234/PalatisSoftPWM/issues/2","id":200746283,"user":{"login":"Palatis","id":992564,"avatar_url":"https://avatars.githubusercontent.com/u/992564?v=3","gravatar_id":"","url":"https://api.github.com/users/Palatis","html_url":"https://github.com/Palatis","followers_url":"https://api.github.com/users/Palatis/followers","following_url":"https://api.github.com/users/Palatis/following{/other_user}","gists_url":"https://api.github.com/users/Palatis/gists{/gist_id}","starred_url":"https://api.github.com/users/Palatis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Palatis/subscriptions","organizations_url":"https://api.github.com/users/Palatis/orgs","repos_url":"https://api.github.com/users/Palatis/repos","events_url":"https://api.github.com/users/Palatis/events{/privacy}","received_events_url":"https://api.github.com/users/Palatis/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T09:04:06Z","updated_at":"2016-03-24T09:04:06Z","body":"arduino is a 8bit mcu, if we try to use more than 8bit to store pwm levels, we have to do uint16_t arithmetic, that's like 2 times slower.\r\nhttp://www.avrfreaks.net/forum/multiply-divide-add-performance-various-data-types\r\n\r\nthe \"timer frequency\" is calculated as `number of brightness levels * pwm frequency`, for example, `256 levels * 60hz = 15360hz` (60hz is an ideal pwm frequency to *NOT* cause visual flicker), on a 16Mhz mcu we have `16Mhz / 15.36Khz = 1041.66 cycles` to finish the task.\r\neach channel takes 4 instructions, plus some overhead (around 10 instructions), if we're targeting 16 channels it's `16 * 4 + 10 = 74 instructions` to be executed every 1041.66 cycles, yields a cpu load of `~7.1%`.\r\n\r\nand say, we now want 512 levels, `512 levels * 60hz = 30720hz`, around `16Mhz / 30.72Khz = 520.83 cycles` to complete each timer isr.\r\nand the timer ISR now take `16 * 8 + 20 = 148 instructions` due to uint16_t arithmetic (512 can't be stored in a uint8_t), the cpu load is now `148 / 520.83 ~= 28.4%`.\r\n\r\neven if we still do 256 levels but store the levels in a uint16_t, the isr load is bumped by a factor of 2.\r\nso `~14%` cpu load.\r\nwell if we can make c++ automatically select optimal storage type for levels we may be able to achieve this without sacrificing performance, however I don't know how......"}}