{"action":"closed","issue":{"url":"https://api.github.com/repos/nathanchantrell/TinyPCRemote/issues/1","repository_url":"https://api.github.com/repos/nathanchantrell/TinyPCRemote","labels_url":"https://api.github.com/repos/nathanchantrell/TinyPCRemote/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/nathanchantrell/TinyPCRemote/issues/1/comments","events_url":"https://api.github.com/repos/nathanchantrell/TinyPCRemote/issues/1/events","html_url":"https://github.com/nathanchantrell/TinyPCRemote/issues/1","id":36746307,"node_id":"MDU6SXNzdWUzNjc0NjMwNw==","number":1,"title":"Calibrating OSCCAL Value","user":{"login":"omersiar","id":6163270,"node_id":"MDQ6VXNlcjYxNjMyNzA=","avatar_url":"https://avatars2.githubusercontent.com/u/6163270?v=4","gravatar_id":"","url":"https://api.github.com/users/omersiar","html_url":"https://github.com/omersiar","followers_url":"https://api.github.com/users/omersiar/followers","following_url":"https://api.github.com/users/omersiar/following{/other_user}","gists_url":"https://api.github.com/users/omersiar/gists{/gist_id}","starred_url":"https://api.github.com/users/omersiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omersiar/subscriptions","organizations_url":"https://api.github.com/users/omersiar/orgs","repos_url":"https://api.github.com/users/omersiar/repos","events_url":"https://api.github.com/users/omersiar/events{/privacy}","received_events_url":"https://api.github.com/users/omersiar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2014-06-29T13:47:59Z","updated_at":"2018-11-17T14:15:18Z","closed_at":"2018-11-17T14:15:18Z","author_association":"NONE","body":"Is it possible to calibrate OSCCAL Value like other projetcs using this code?\n\n// do a binary search in regions 0-127 and 128-255 to get optimum OSCCAL\n    for(region = 0; region <= 1; region++) {\n        frameLength = 0;\n        trialCal = (region == 0) ? 0 : 128;\n\n```\n    for(step = 64; step > 0; step >>= 1) { \n        if(frameLength < targetLength) // true for initial iteration\n            trialCal += step; // frequency too low\n        else\n            trialCal -= step; // frequency too high\n\n        OSCCAL = trialCal;\n        frameLength = usbMeasureFrameLength();\n\n        if(abs(frameLength-targetLength) < bestDeviation) {\n            bestCal = trialCal; // new optimum found\n            bestDeviation = abs(frameLength -targetLength);\n        }\n    }\n}\n\nOSCCAL = bestCal;\n```\n\n}\n\n=======================================================or\n\n/\\* Calibrate the RC oscillator to 8.25 MHz. The core clock of 16.5 MHz is\n- derived from the 66 MHz peripheral clock by dividing. Our timing reference\n- is the Start Of Frame signal (a single SE0 bit) available immediately after\n- a USB RESET. We first do a binary search for the OSCCAL value and then\n- optimize this value with a neighboorhod search.\n- This algorithm may also be used to calibrate the RC oscillator directly to\n- 12 MHz (no PLL involved, can therefore be used on almost ALL AVRs), but this\n- is wide outside the spec for the OSCCAL value and the required precision for\n- the 12 MHz clock! Use the RC oscillator calibrated to 12 MHz for\n- experimental purposes only!\n  */\n  static void calibrateOscillator(void)\n  {\n  uchar       step = 128;\n  uchar       trialValue = 0, optimumValue;\n  int         x, optimumDev, targetValue = (unsigned)(1499 \\* (double)F_CPU / 10.5e6 + 0.5);\n  \n  /\\* do a binary search: _/\n  do{\n      OSCCAL = trialValue + step;\n      x = usbMeasureFrameLength();    /_ proportional to current real frequency _/\n      if(x < targetValue)             /_ frequency still too low _/\n          trialValue += step;\n      step >>= 1;\n  }while(step > 0);\n  /_ We have a precision of +/- 1 for optimum OSCCAL here _/\n  /_ now do a neighborhood search for optimum value _/\n  optimumValue = trialValue;\n  optimumDev = x; /_ this is certainly far away from optimum */\n  for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){\n      x = usbMeasureFrameLength() - targetValue;\n      if(x < 0)\n          x = -x;\n      if(x < optimumDev){\n          optimumDev = x;\n          optimumValue = OSCCAL;\n      }\n  }\n  OSCCAL = optimumValue;\n  }\n"}}
{"actor":{"display_login":"omersiar"}}