Teensy 3.2 Snooze and CAN not working together

Status
Not open for further replies.

Shadrach

Member
Hey all, I'm very new to the whole Arduino/teensy/electricity game so I apologize in advance if these are eye-roll worthy questions.

I'm currently working on a Teensy that essentially controls power within a CAN logging system.
The basic layout is as follows;

Teensy reads voltage
if car voltage is high charge the internal battery
if car voltage is low switch to only internal battery
if internal battery is low turn off the logging and switch to a low power mode (as to avoid killing the battery if the system is left on while the car is off)

The problem I'm consistently running into is that once the teensy goes to sleep it either never wakes up, or wakes up instantly on loop. I'm sure this has something to do with the CAN requirements at startup, but my lack of knowledge is getting in the way of actually figuring it out.

The teensy is running at 48 MHZ as a keyboard USB (to turn off the logging system)

I'm leaving out A LOT of code that isn't important to the issue.
Code:
#include <Snooze.h>
SnoozeAlarm alarm;
SnoozeUSBSerial usb;
SnoozeBlock config(alarm,usb);

#include <FlexCAN.h>
#include <kinetis_flexcan.h>
static CAN_message_t msg;
There's some variable setup that goes in here but doesn't impact the snooze issues.
Code:
void setup() {
  while (!Serial);
    delay(100);
    Serial.println("Starting...");
    delay(100);
    
alarm.setRtcTimer(0, 0, 10);// hour, min, sec

Can0.begin(500000);
analogReadRes(12);

idx = 0;
}
A lot of code goes in the loop including the analog reads and logic statements that decide what the teensy should do and the functions that actually control things like outputs to relay switches and keyboard commands to the computer, I'm leaving that stuff out because it's working fine and isn't overly important to the actual problem.
Code:
void loop() {
  int who = 0;
  Can0.end();
  delay (200);
            Serial.print("NAPPING FOR: ");
            delay(5);
            Serial.print(TimerLength);
            delay(5);
            Serial.println(" SECONDS");
            delay(10);
      who = Snooze.deepSleep(config);
      Can0.begin(500000);
      TimerLength=TimerLength+1;
      delay (200);
}


Any advice would be greatly appreciated!
Also, huge thank you to Duff for making such an awesome snooze library, even with my inability to code I can see how awesome the work he's put into it is :)
 
UPDATE:

I have it working now;
Still running at 48MHZ as a keyboard. I think it came down to the order in which I was beginning and ending Can0 and how I went about restarting it.

Code:
#include <Snooze.h>
SnoozeTimer timer;
SnoozeUSBSerial usb;
SnoozeBlock config(timer,usb);
int TimerLength = 10000;

#include <FlexCAN.h>
#include <kinetis_flexcan.h>
static CAN_message_t msg;

void setup() {
  while (!Serial);
    delay(100);
    Serial.println("Starting...");
    delay(100);
    
timer.setTimer(TimerLength);

Can0.begin(500000);
analogReadRes(12);

idx = 0;
}

void loop() {
  int who = 0;
            Serial.print("NAPPING FOR: ");
            delay(5);
            Serial.print(TimerLength/1000);
            delay(5);
            Serial.println(" SECONDS");
            Can0.end();
            Serial.end();
            delay(200);
who = Snooze.hibernate(config);
      elapsedMillis time = 0;
          while (!Serial && time < 1000) {
          Serial.write(0x00);// print out a bunch of NULLS to serial monitor
          }
              delay(200);
      static CAN_message_t msg;
      Can0.begin(500000);
      Serial.begin(9600);
    delay(1000);
    timer.setTimer(TimerLength);
    TimerLength=TimerLength+100;
    delay(10);
}
 
It looks like you got it working but do you want to add 100 msec to the timer each time you wake up? If not then you don't have to update the "TimerLength" or reset the timer it will keep that value for you.
 
It looks like you got it working but do you want to add 100 msec to the timer each time you wake up? If not then you don't have to update the "TimerLength" or reset the timer it will keep that value for you.

Thanks Duff! yeah, the increasing sleep period is a part of the broader design... I probably should've left it out for the sake of clarity in this forum.
 
The code seems to be working as expected, but the teensy still drains a 12v battery over night.
The 12V is stepped down with a 94% efficient power switcher, and the teensy low power op kicks on when the battery hits 12.2V. Should it really be killing the battery over night? the teensy should, ideally, last several days.

The battery specs are; 12V lithium Battery, fully charged at about 13V, 51.2 Watt Hours.
The Teensy reads voltages and constructs/sends CAN messages until the battery hits about 12.2V, then it cycles sleeping and stops transmitting messages.

Any suggestions on how to fix this/am I doing something wrong?
 
Last edited:
Quick Update:

I found that after a while of the sleeping it begins instantly looping without ever sleeping which could account for the battery drop. Has anyone else found that snooze stops working after several loops?
 
Status
Not open for further replies.
Back
Top