Hi Henrik,
Just to thank you again. Installed the 32.768KHz xtal with a 12pF cap on each leg to earth and it now all runs. Also, I now have a clearer head and all the settings now make sense in my head. Current drops from around 2mA for my test circuit to about 100uA, which I believe is roughly the norm. This should DRAMATICALLY increase the lifetime of the battery!
The code I now have is below for the benefit of others.
Best regards
Jimbo
Code:define OSC 16 DEFINE HSER_BAUD 19200 DEFINE HSER_CLROERR 1 ' Auto clear over-run errors DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h blue_LED var portb.5 'prototype =a3, sleep test cct b5 trisa = %00000000 trisd = %00000000 trisc = %00000000 trisb = %00001000 adcon0.0 = 0 ANSELA = 0 ANSELB = 0 ANSELC = 0 ANSELD = 0 ANSELE = 0 ADCON1 = 15 tmp1 var byte tmp2 var byte p1 var byte p2 var byte p3 var byte seconds var byte pausetime var byte i2cSDA VAR PORTD.1 i2cSCL VAR PORTD.0 pause 50 i2cwrite i2cSDA,i2cSCL, $d0, $3e, [64] ' switch off the gyroscope (save 6.5 mA) pauseus 5 'I2CWRITE i2cSDA,i2cSCL, $a6, $2c, [%1000] 'accelerometer pauseus 5 OSCCON = OSCCON | %11110000 ' set internal clock to 16 MHz incase of switchover On Interrupt Goto myint PMD0 = %10111110 ' leave UART1 and Timer1 enabled PMD1 = %10111111 ' leave MSSP1 (SPI) enables PMD2 = %11111111 ' disable all these peripherals IPR1.0 = 1 INTCON = %11000000 ' global int enable OSCCON.7 = 0 ' CPU goes to IDLE when SLEEP command given T1CON.3 = 1 ' secondary (external) oscillator enable bit T1CON.7 = 1 ' timer 1 clock source is oscillator (external xtal) T1CON.6 = 0 ' """""""""""""""""""""""""""""""""""""""""""""""""" T1CON.5 = 0 ' prescale value set to 1:1 T1CON.4 = 0 ' """"""""""""""""""""""""" T1CON.2 = 1 ' do not synchronise external clock input with system clock T1CON.1 = 0 ' 2x 8 bit timer value output TMR1H = $fc ' Clear timer1 count TMR1L = 0 ' Clear timer1 count PIR1.0 = 0 ' Clear over-flow flag before enable PIE1.0 = 1 ' timer 1 enable interrupt T1CON.0 = 1 ' enable timer 1 lp: ' do something in this loop sleep 10 ' and then go to sleep goto lp stop Disable myint: hserout[$d,$a,"Interrupt!"] high blue_led pause 1 low blue_led TMR1H = $fc TMR1L = $0 PIR1.0 = 0 ' reset interrupt request flag Resume Enable




Bookmarks