Teensy 3.1 and CMP0 or CMP1 modules - lockup

Status
Not open for further replies.

johm

New member
Hello All
First post.

My name is John Maher, and I tinker around with micros and small scale electronics as a hobby . I am a software engineer by trade, programming now mostly in
managed OO COBOL and C#, but have many years of coding in everything from binary using patch plugs , through assemblers, c, c++ etc.

Purchased a Teensy 3.1 a couple of weeks ago, and really enjoying it . Cracking little thing :) , and a nice thriving community here as well.
using teensyduino 1.18 .

I have already interfaced a touch LCD to it, and am busy going through the micros functionality , learning what it can and can't do ,

I am busy trying to get the comparator module working . I want to use it to detect an analog signal and measure the frequency as accurately as possible. The comparator seems ideal as it can trigger at a threshold and generate an interrupt.

The problem :

If I try and read or touch any of the comparator registers, e.g. CMP0_CR0, the Teensy locks up .
For example, taking the stock Serial Hello World example that comes with Teensyduino, I compile and run it, and it works.
If I add in a line that accesses any of yhr the CMP registers, it locks up.

Example

Code:
void setup()   {                
  Serial.begin(38400);
}

void loop()                     
{
  delay(10000); // wait for my fingers to open the serial monitor.
    Serial.println("Starting");
 
   //  CMP0_CR0=0; // either of these two lines will cause the teensy to lock up.
   uint8_t var = CMP0_CR0; // CMP0_CR0 is defined as an 8 bit unsigned integer ( char) .
  // if you try it with the ADC control register, it works.
  //uint32_t var = ADC0_CFG1; // ADC0_CFG1 is defined as a uint32_t (unsigned long integer) 
  for( ; ; )
  {
    char buffer[30]={};
    sprintf(buffer,"Hello World - value is %d",var);
    Serial.println(buffer);
    delay(1000);
  }
}

The freescale application notes state that CMP0_CR0 and CMP0_CR1 need setting to 0 first, then the rest of the setup follows . I cant get past initialising the control registers .

Any help or guidance is most appreciated.

Thanks for the help in advance.

Cheers

John
 
Last edited:
IIRC various modules in the processor have their own clock which needs to be enabled before they can function. For the comparator, I think you need this in setup():
Code:
SIM_SCGC4 |= SIM_SCGC4_CMP;

Pete
 
Works perfectly. Looked extensively thru the K20 manual to see why I couldn't access any of the comparator registers, but didn't see this.
Forums and experts- what would we do without them?
 
Status
Not open for further replies.
Back
Top