Don't like ads? PRO users don't see any ads ;-)
Guest

sourceboost-12f683-cout

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 4.40 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Hi,
  2.  
  3. I've spent the last few days trying to migrate to BoostC but it seems that 6bit GPIO chips are not fully implemented.
  4.  
  5. OS WIn7
  6.  
  7. SourceBoost IDE 7.05
  8.  
  9. 12F683
  10.  
  11. The comparator uses GP0,GP1,GP2 and an internal voltage reference to function.
  12.  
  13. It can be configured in many ways but it's output (COUT) is always available as bit6 of the CMCON0 register.
  14.  
  15. CMCON0 :  [u] [cout] [u] [cinv] [cis] [cm2] [cm1] [cm0] (page 56 of the 12F683 pdf - 41211d)
  16.  
  17. I'm setting the comparator up in mode 6 (cm2:0<110>) for the first example and mode 5 (cm2:0<101>) for the second.
  18.  
  19. Both use the internal reference. Mode 6 does not put COUT on GP2, Mode 5 does.
  20.  
  21. Regardless, COUT should be available internally all the time.
  22.  
  23. The examples below illustrate the hair pulling and suffering I endured before I facepalmed a WORKAROUND (yes I know - I read the EULA - it's ok)
  24.  
  25. Facepalm workaround
  26.  
  27. #define COMPOUT         cmcon0.6
  28.  
  29. But of course...
  30.  
  31. #define COUT         cmcon0.6
  32.  
  33. will not work because COUT is already taken by the compiler that refuses to implement it :rolleyes:
  34.  
  35. In both examples my dev board's pot is hard wired to GP0(AN0:CIN+).
  36.  
  37. I am multiplexing it as an input (cis<1>).
  38.  
  39. Here is an example of how COUT is not available internally.
  40.  
  41. [CODE]#include         <system.h>
  42.  
  43. #pragma         CLOCK_FREQ 20000000
  44.  
  45. #pragma DATA    _CONFIG, _WDT_OFF & _CP_OFF & _HS_OSC & _MCLRE_OFF
  46.  
  47. #include "firsttry.h"
  48.  
  49. //Labels for General Purpose ports
  50.  
  51. //0 pot input from PCB
  52.  
  53. #define LED         gpio.1
  54.  
  55. //MAIN
  56.  
  57.    
  58.  
  59. void main()
  60.  
  61. {
  62.  
  63.     trisio     = 0b000001;        //GP0(AN0) as input
  64.  
  65.     // cmcon0 [cinv][cis][cm2][cm1][cm0]
  66.  
  67.     cmcon0     = 0b01110;         // internal vref // CIN+ input multiplexed to GP0(AN0) // COUT internal only - aka mode 6
  68.  
  69.     ansel      = 0b0001;        // allow GP0 to be analogue      
  70.  
  71.     vrcon     = 0b10000001;     // internal vref HIGH range to allow pot to move mid range
  72.  
  73.     delay_us(20);    // just to allow things to settle
  74.  
  75. // This should cause the LED to light when COUT  is triggered by the pot input
  76.  
  77. // but it does not do so
  78.  
  79.     while(1){
  80.  
  81.     LED = COUT;
  82.  
  83.     }
  84.  
  85. }[/CODE]
  86.  
  87. Here is an example of what does work however it requires COUT to be on GP2 and then have a my variable (COMPOUT) defined to mirror that port.
  88.  
  89. (this of course uses port GP2 which defeats the object of using a low pin count device - see facepalm solution above)
  90.  
  91. [CODE]#include         <system.h>
  92.  
  93. #pragma         CLOCK_FREQ 20000000
  94.  
  95. #pragma DATA    _CONFIG, _WDT_OFF & _CP_OFF & _HS_OSC & _MCLRE_OFF
  96.  
  97. #include "firsttry.h"
  98.  
  99. //Labels for General Purpose ports
  100.  
  101. //0 pot input from PCB
  102.  
  103. #define LED         gpio.1
  104.  
  105. #define COMPOUT         gpio.2 // **ADDED BECAUSE COUT IS NOT AVAILABLE INTERNALLY - MUST BE PATCHED PHYSICALLY**
  106.  
  107. //MAIN
  108.  
  109.    
  110.  
  111. void main()
  112.  
  113. {
  114.  
  115.     trisio     = 0b000001;        //GP0(AN0) as input
  116.  
  117.     // cmcon0 [cinv][cis][cm2][cm1][cm0]
  118.  
  119.     cmcon0     = 0b01101;     // internal vref // CIN+ input multiplexed to GP0(AN0) // COUT on GP2 - aka mode 5 // **CHANGED**
  120.  
  121.     ansel      = 0b0001;        // allow GP0(AN0) to be analogue      
  122.  
  123.     vrcon     = 0b10000001;     // internal vref HIGH range to allow pot to move mid range
  124.  
  125.     delay_us(20);    // just to allow things to settle
  126.  
  127. // This will cause the LED to light when COUT is triggered by the pot input
  128.  
  129. // but only because it's made available on a real pin (GP2) and assigned to a variable
  130.  
  131.     while(1){
  132.  
  133.     //LED = COUT; // does not work and yet COUT cannot be redefined - i.e. it's been assigned but not implemented
  134.  
  135.     LED = COMPOUT;
  136.  
  137.     }
  138.  
  139. }[/CODE]
  140.  
  141. Other things like cinv/cis/cm2/cm1/cm0 cannot be set individually and of course result in compile errors.
  142.  
  143. The 12F683 and similar PICs are very powerful and useful little devices.
  144.  
  145. I'm currently generating a video signal from scratch (in ASM - not an overlay but actual video source) and now need to detect an incoming video signal's presence, or lack thereof, which obviously needs the comparator.
  146.  
  147. All the difficult timing is done in ASM. I just need to patch some logic into the application which is what C would be used for.
  148.  
  149. If this is not a bug and I'm doing something wrong then please feel free to move/retitle this post.
  150.  
  151. But as far as I can tell you guys think the 8 legged PICs are not worthy of being concidered BIG BOYS (the plugins have ignored the GPIO for about 4 yrs and counting) -_-
  152.  
  153. thanks