SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By kaleem
#24482
hello everybody,i have written a c code function which involves watchdog timer interrupt,ADC conversion and sending the data to ouput port of controller.i am using a At tiny13 microcontroller,but firs´t i am testing on olimex board,here i am making led high each time the data is send to the output port,when i tested it out on olimex the led is blinking continuosly,i thiink the watchdog function is not working can anybody help me out.please let me know how to cross check the functionality of this code,if had checked it on avr studio simulator,simulation is fine.

heres the code

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/iom128.h>
#define F_CPU=16;
#define TEMP=R16;
void data_send(void);
void init(void);
void delay_loop(unsigned char);
unsigned char data[3]; // data packet
unsigned char counter;
unsigned char i;
unsigned char x;
unsigned char timecount = 0;
unsigned char reset_no;
/* ADC interrupt service routine*/
SIGNAL(SIG_ADC)
{ //data[1] =ADCH; // read MSB into variable
data[1]=0xaa;
PORTB = 0X00; // disable temp sensor
data_send(); // send packet data
ADCSRA= 0x00; // disable ADC
WDTCR= 0x0F; // WDT enable;reset mode;
MCUCR= 0x31; // enable power down sleep ;
//sleep_mode();
}

void delay_loop(unsigned char us)
{for(;us>0;us--)
{asm("nop");}
}


void delay_loop1(unsigned long us)
{for(;us>0;us--)
{asm("nop");}
}

void init(void)
{DDRA= 0xFF;
ADCSRA= 0x00; // disable ADC
ACSR= 0x81; // Anlog comparator disable
wdt_disable();
//DIDR0= 0x3F; // Digital input register enable
data[0]=0xFF;
data[2]=0xFF;
counter=0; // initial value
}

void data_send(void)
{for(i=0;i<24;i++)
{ wdt_disable();
if(data[counter/8] & (01<<(counter%8)))
{ PORTA= 0X40;
delay_loop1(220);
PORTA = 0X00;
delay_loop1(220);}
else{//PORTA= 0X00;
delay_loop1(220);
//PORTA= 0X40;
delay_loop1(220);}
counter++;}
}



void main(void)

{
init();
WDTCR=0x0F;
while(1)
{
asm volatile("STS reset_no,R16");
asm volatile("INC R16");
if(reset_no==15)
{
//WDTCR=0x0F;
//WDTCR=0x00;
goto noteq; }
else
{ADCSRA= 0x00; // disable ADC
WDTCR= 0xF; // WDT enable;reset; 1.8s;
MCUCR= 0x31; // power down mode
//sleep_mode();
}
}
{
noteq:asm volatile("CLR R16");
PORTB = 0X20; // enable temp sensor
delay_loop(30);
ADMUX= 0xE6; // Vref (1.1v) , channel pB3
ADCSRA= 0xEF; // enable ADC ; start conv.
sei(); // interrupt enable
WDTCR= 0x00; // WDT enable;reset;
MCUCR= 0x21; // sleep enable ;idle mode
sleep_mode();
//while (1);
}
}

thank you
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]