Jump to content

scud21

EstablishedMember
  • Content Count

    20
  • Joined

  • Last visited

Everything posted by scud21

  1. I need software reset too..hey this one really works! Thanks!
  2. hi i have a main.c and two header files (initialization.h and function.h). the summary is i integrate all my modules and turn them into function/process so that my main.c program will just call them. my function/process use timers. heres the problem: when i put the "void interrupt(void)" process in the function.h it compiles successfully but it doesn't work. but when i put "void interrupt(void)" process in the main.c it compiles error, saying here are my sample code: main.c #include <function.h> //Target PIC16F877 configuration word #pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _XT_OSC & _CP_OFF //Set clock frequency #pragma CLOCK_FREQ 4000000 void interrupt() { //Handle timer0 interrupt if(intcon & (1<<T0IF)) { /************************for RR_function************************/ RRcounter++; if(RRcounter == 49){ // already 0.05 second real_time++; //same as 1/4 of big box RRcounter = 0; } clear_bit( intcon, T0IF ); // clear timer 0 interrupt bit tmr0 = 0x00; /***************************************************************/ } } void main( void ) { trisc = 0x00; portc = 0x00; portc.4 = 1; RR_function(); while(1) portc.3 = 1; } function.h #include <initialization.h> void ADC_init() { trisa.0 = 1; adcon0 = 00000000b; /* Fosc/2, AN0, right justified*/ adcon1 = 10001110b; clear_bit(pir1, 6); //clear ADIF clear_bit(pie1, 6); //ADC interrupt disabled set_bit(intcon, 6); //set PEIE set_bit(intcon, 7); //set GIE } void ADC() { adcon0.0 = 1; adcon0.2 = 1; //starts ADC while(adcon0.2); // wait until conversion is done } void timer0_init() { /*---1:4 prescalar---*/ option_reg.2 = 0; option_reg.1 = 0; option_reg.0 = 1; /* ------------------ */ option_reg.5 = 0; // internal clk source option_reg.3 = 0; // prescalar assigned to timer0 //intcon.5 = 1; // enables timer0 interrupt tmr0 = 0x00; } void timer0_go(){ intcon.5 = 1; } void timer0_stop() { intcon.5 = 0; } void RR_function(void){ //unsigned long heart_rate = 0; bit flagR1 = 0; bit flagR2 = 0; unsigned int rate = 0; ADC_init(); trisc = 0x00; portc = 0x00; ADC: ADC(); MAKESHORT(ewan, adresl, adresh); if(ewan > Nullplus){ first_frame = ewan; ADC2: ADC(); MAKESHORT(ewan, adresl, adresh); if(ewan >= first_frame){ first_frame = ewan; goto ADC2; } else if(ewan < first_frame){ peak_temp = first_frame; if((peak_temp<=R_peak1)&&(peak_temp>=R_peak2)){ if(flagR1 == 1){ timer0_stop(); flagR2 = 1; portc.1 = flagR2; goto fin; } if(flagR1 == 0){ flagR1 = 1; portc.0 = flagR1; timer0_init(); timer0_go(); delay_ms(20); goto ADC; } } } } goto ADC; fin: delay_s(1); while(1){ unsigned int temp; temp = 300/real_time; rate = temp*4; //portc = rate; if(rate < 60){ portc.7 = 1; } if((rate >= 60) && (rate <= 100)){ portc.6 = 1; } if(rate > 100){ portc.5 = 1; } } } initialization.h #include <system.h> /***************R wave initialization***************/ unsigned short R_peak1 = 0x0256; // 2.92 unsigned short R_peak2 = 0x01DB; // 2.32 unsigned int RRcounter = 0; unsigned int real_time = 0; /***************************************************/ unsigned short Nullplus = 0x00A8; // 820mV unsigned short Nullminus = 0x006B; // 520mV unsigned short first_frame = 0x0000; // temporary first detection of a desired signal unsigned short last_frame = 0x0000; // temporary last detection of a desired signal unsigned short peak_temp = 0x0000; // temporary peak detected unsigned short ewan = 0; where should i put "void interrupt(void)"? any comments/suggestions?? regards, scud
  3. just a reminder: microcontrollers will not accept negative AC voltages (they might get damage --> based from my experience). try to use level shifter or a clipper. And another thing, put bypass capacitors in your PIC's regulator. here is a helpful link:
  4. XT = Temperature Compensated Crystal !CP = No comparators !WDT = No Watchdog Timer !PWRT = ... No Power on reset? BODEN = BrownOut Detect LPV = Low Voltage Programming !CPD = No clear power down detect ? WRT = Write Protect !DEBUGGER = No Debugger adon enables/disables AD in the adcon register No, your pragma line did not affect the adcon register, and yes you need to disable AD if you want to use it as a regular IO port. <{POST_SNAPBACK}> i think: !CP = disable Code Protect XT = use crystal oscillator instead of RC, internal osc, etc **for the rest look at the WINPIC's device config tab That pragma line is use by your WINPIC to configure the device config before uploading the hex file on your microcontroller
  5. what is the limit size of the hex file that i can load to my microcontroller? let say, for pic16f877a?
  6. i have simulated adc in pic16f877a in sourceboost ide and there were no problems or what so ever...
  7. why not try to use an interrupt routine in your function? when an interrupt occurred, have your conditional statements handle where you want to go in your main.
  8. look at the datasheet and in the internet about timer (timer0, timer1, etc.). i know they are also used to generate PWM in PIC's
  9. i forgot, the counter and realtime variables are both global
  10. well i can't give you my exact code in my heart module but here is a simple algorithm that i develop. void interrupt(){ if(tmr0 interrupt occured) { counter++; if(counter==49){ //already 0.05 second realtime++; counter = 0; } clear interrupts of timer0; } } void main() { /* put the initializing stuff here for ADC and timer0 */ while(1){ ADC() //do the ADC here /* do the parameter comparison here */ if(if the signal digitized is null) goto ADC again; if(first pulse is detected){ start timer0; goto ADC again; } if(second pulse is detected){ end timer0; } } } my clock is 4Mhz, WDT is off. im using internal clock for timer0 clk with prescalar of 1:4. it was said in my datasheet that an execution of an instruction is 4/Fosc. therefore 4/4Mhz is 1us. it means that an increment in timer0 is 1us. since timer0 is an 8 bit register, when an interrupt has occured there were 256us*4. i multiply 4 because of the prescalar. to make it short here is the equation: Y = A*X*Z where: Y - desired time A - 4/Fosc*2^n (n is number of bits of the timer) X - prescalar reciprocal Z - integer of a corresponding time looking from the algo, i got the integer 49 from this equation that corresponds to 0.05 seconds rounded up. the calculation of real time and frequency is up to you. take note that if your timer requires postscalar, just set it to 1:1 in order to use this kind of approach. i hope this helps you.
  11. if you,ve measured the time, you can derived the frequency from it. In my module that measure heart rate, i used timer0 of PIC16f877a. what is your target microcontroller anyway?
  12. thanks for replying asmallri. i figured out what was wrong. it's not in sourceboost boostc but in my bread board. its loosen in the back. damn that breadboard..hahahah please disregard this stupid post of mine.
  13. hi my code works in simulation but in the real world it doesn't. my target PIC is PIC16f877a, 4Mhz Xtal Oscillator. before going specific here is my code: #include <system.h> #include <boostc.h> //Target PIC16F877 configuration word #pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _XT_OSC & _CP_OFF //Set clock frequency #pragma CLOCK_FREQ 4000000 unsigned short R_peak1 = 0x0265; unsigned short R_peak2 = 0x01ea; bit flagR1 = 0; bit flagR2 = 0; unsigned int RRcounter = 0; unsigned short Nullplus = 0x00f4; unsigned short Nullminus = 0x0082; /* Fosc/2, AN0, right justified*/ void ADC_init() { trisa.0 = 1; adcon0 = 00000000b; adcon1 = 10001110b; clear_bit(pir1, 6); //clear ADIF clear_bit(pie1, 6); //ADC interrupt disabled set_bit(intcon, 6); //set PEIE set_bit(intcon, 7); //set GIE return; } void ADC() { unsigned short comb; adcon0.0 = 1; adcon0.2 = 1; //starts ADC while(adcon0.2); // wait until conversion is done } void timer0_init() { /*---1:4 prescalar---*/ option_reg.2 = 0; option_reg.1 = 0; option_reg.0 = 0; /* ------------------ */ option_reg.5 = 0; // internal clk source option_reg.3 = 0; // prescalar assigned to timer0 //intcon.5 = 1; // enables timer0 interrupt tmr0 = 0x00; } void timer0_go(){ intcon.5 = 1; } void timer0_stop() { intcon.5 = 0; } void interrupt(void) { //Handle timer0 interrupt if(intcon & (1<<T0IF)) { //RRcounter++; clear_bit( intcon, T0IF ); //clear timer 0 interrupt bit tmr0 = 0x00; } } void main( void ) { unsigned short ewan = 0; unsigned long heart_rate = 0; int RR_interval = 0; ADC_init(); trisc = 0x00; portc = 0x00; portc.3 = 1; portc.4 = 1; ADC: ADC(); MAKESHORT(ewan, adresl, adresh); //LOBYTE(portc, ewan); //HIBYTE(portc, ewan); /*if((ewan<=Nullplus)&&(ewan>=Nullminus)){ //clear_bit(pir1, ADIF); goto ADC; }*/ //Detect peak only if flags are not set if((ewan<=R_peak1)&&(ewan>=R_peak2)){ //clear_bit(pir1,ADIF); if(flagR1 == 1){ timer0_stop(); flagR2 = 1; portc.1=1; goto fin; } if(flagR1 == 0){ flagR1 = 1; //portc.0=1; timer0_init(); timer0_go(); goto ADC; } //goto ADC; } goto ADC; fin: while(1){ if(flagR2==1){ portc.0 = 1; portc.1 = 1; } portc.7 = 1; portc.6 = 1; delay_s(1); portc.7 = 0; portc.6 = 0; delay_s(1); } } description: this code is used to detect two peaks. R_peak1 and R_peak2. if R_peak1 was detected, it will set flagR1 then go to ADC again and wait for another peak which is R_peak2. after it has detected R_peak2, flagR2 will be set then it will go to fin to do the led blinking to check if it really works. in the simulation mode it really works as i wanted it. (portc.0 , 1, 3, and 4 should stay ON while portc.6 and 7 should blink). Now heres the problem, portc.0 , 1 , 6 and 7 blinks together when R_peak is detected. this algo should only detect two R_peak but i think what it does in the real world is it keeps detecting R_peaks. i suspect that it doesn't go to the last while loop but why does portc.6 and 7 blinks? I suspect it has something to do with the interrupt routine. i tried removing it in ny code but it was also the same so i though it does not have something to do with the interrupt routine. Actually this algo will be used to detect heart rate that is why i ask from my previous question about integer to binary. well this is another problem but i'll ask it again after this one is done. thanks for reading my long post and i hope you had idea what was behind my problem. regards, scud
  14. is there a built in function in sourceboost boostc converting int to binary?
  15. use PWM, try to look up in search engines about PWM and how to program it. there's a lot of sources out in the net.
  16. Try this one: #include <system.h> //#include <pic16f877a.h> #define FOSC 10000000L #pragma DATA _CONFIG, _CP_OFF & _DEBUG_OFF & _CPD_ON & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC & _WRT_OFF void main() { trisd.0 = 0; while(1){ portd.0 = 0; delay_s(1) } }
  17. Thanks picxie for your suggestion. i'll try it and hope it works. thanks again regards, scud
  18. HI our thesis deals with pic16f877a and we use it for ADC and analyzing process. i am having hard time with capturing the digitized signals. we digitized the gained signal from a heart simulator. well here are my questions: ----> how can i tell my program that i wanted to digitized one full cycle only or two? ----> where can i store the digitized full cycle so that i can check on it afterwards? variable or in an external memory or flash/eeprom? regards, scud
×
×
  • Create New...