Jump to content

ra68gi

EstablishedMember
  • Content Count

    229
  • Joined

  • Last visited

Posts posted by ra68gi


  1. There could be two problems:

     

     

    [*]I seem to recall that when you progam a pin to be an external interrupt input, it is no longer an input port pin.

     

    Hi trossin, actually u can use the external interrupt pin as input pin but only in the ISR function of the interrupt (when the flag is not cleared).

    Many spi device work that way.

    Regards

    Raghunathan.P


  2. Thank You It's a start. I am looking for a software based SPI, but I could back step a little more and try this on hardware SPI platform then modify to software bit bang.

    One question I have yet to figure out. How do I use the templates to define more than one? For example what does code look like for using 2 LCD's (lcd_driver.h) or 2 Serial ports (rs232_driver.h) or two I2C devices (i2c_driver.h)

     

    TimC

    Tim, If u need to connect more than one LCD to ur mico connect them in parallel & multiplex them using some thing like using chip-select pin.

    Only one driver file can be used. May be u need to write ur own driver to support parallel devices working on different i/o pins.

    Most spi device will have chip-select pin. connect all devices in parallel(in, out & clk)& use different i/o pins for multiplexing the chip-select pin.

    Regards

    Raghunathan.P


  3. Have anyone write code/lib to use USB Serial port on PIC18F4550? I mean that a virtual RS232 COM port is created.

     

    Hi,

    Have u not tried the picpack lib(pic_serial.c)? I tried it with 2550 & it works.

    Its such a waste of time trying to make a virtual serial port from ur usb device.

    USB is used for hi speed communication & u can make HID class device thro' which

    u can transfer data at a rate of 40-50 characters per millisecond.

    Sending variables from pic to PC is so easy using the HIDMAKER tools from tracesystem.

    try this out...

    http://tracesystemsinc.com/all-usb-product...ucts-alias.html

     

    Regards

    Raghunathan.P

    Edit : Sorry Harris I did'nt realise this was a very old thread.


  4. Raghunathan,

     

    I would be very happy to work with you on integrating HID maker, at least, if what you mean by that is producing SourceBoost C as opposed to Microchip C code. It looks like a very neat tool. We have a USB stack up and running in SourceBoost C and will be doing some development work on that over the next few weeks.

     

    cheers

    Ian.

     

    Long time ago I had asked Dr.Bob(Robert Miller) of Trace Systems if they could integrate BoostC compiler. I think Pavel & Dave should decide on this.

    HIDMAKER32 is shortly expected & they will support most USB microcontrollers from the 8bit to 32bit device.

     

    Regards

    Raghunathan.


  5. I'm not new to pic programming, but I *am* new to USB programming. I have looked all over the place for a simple usb interface that will allow me to communicate with the pc using pic18f4553. I have found some snippets of code, but they won't compile or won't run.

     

    I have no real understanding of how to make this thing work with a PIC. Is there anyone eho has a very simple listing that will compile and run? I can't even get the computer to realize that a device has been connected.

     

    Just so you know, I have sourceboostC, but I am currently working with mikrobasic. I am certain I can port it over, but so far I have no idea what I'm doing. USB is very confusing to me. Can somone please help me?

     

    Hi,

    for all those who find USB difficult can try a simpler way of implimenting USB in ur PIC projects.

     

    http://tracesystemsinc.com/all-usb-product...ucts-alias.html

     

    Dave & Pavel, it will be nice if BoostC can be integrated in HID maker.

     

    Regards

    Raghunathan.P


  6. As reg68gi said about get 24 bit value from spi, in the function IncCounter() instead of temp32++, we can have:

    temp32 << 1;

    temp32.BIT0 = SPIBIT;

    Of course, if we talk about few variables, is preferable use 32 bit vars even with the waste of one byte by each.

     

    The objective of this is to see if some one have an more simple way to do this job.

     

    Regards,

    joli

     

    Hi Joli, acquiring 24bit signed data & storing it in 32bit signed can be a bit confusing. My approach is like this.. First I test if its MSB(24bit signed) is a 1.

    If its 1 then its a signed data. I store the rest of the bits in our normal 32bit(long) unsigned type. Then on the long data I do a 2's compiliment. finally to

    get the signed 32 bit data, I multiply it with -1. Here is an example done on 18bits of data. The rest of the adc bits where purposefully truncated.

    u can modify the code for 24bit signed.

    unsigned long adc_counter, adc_counter1;
    signed long adc_buff1;
    
       if(adc_digit_sign_flag==1)			  //If the MSB of the 24bit signed data is a 1 then..do 2's compliments.
    	{
    	  adc_counter1 = adc_counter;
    	  adc_counter1 = ~ adc_counter1;  // 1's compliment.
    	  adc_counter1 = adc_counter1 & 0x003FFFF; // 0x003ffff;0b00000000000000111111111111111111;rest of the bits other than the bits we use must be 
    																	  // forced to zero.
    	  adc_counter1 += 1;	   // 2's compliment.						  
    	 }
    
       if( adc_digit_sign_flag == 1)	// set a flag for MSB of the 24bit signed data. convert it into 32bit signed l_adc_buff1 if the flag is 1.
    	  {
    		adc_buff1 = (-1)* adc_counter1;
    	  }

    I hope the above code can help u come out with a method of storing 24bit signed data.

    Regards

    Raghunathan.P


  7. There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.
    24 bit floats ??

     

    Regards

    Dave

     

    Some ADCs store the adc results (24bit) in signed 2s compliment format. The datas are usually sent out via SPI. In such case a it can be a little helpful if we could directly load the value into such data types.

     

    Regards

    Raghunathan.P


  8. The following aliases are not defined into the PIC16F1933.h include file.

    Just FYI.

     

    volatile char tmr4				   @TMR4;
    volatile char pr4					@PR4;
    volatile char t4con				  @T4CON;
    volatile char tmr6				   @TMR6;
    volatile char pr6					@PR6;
    volatile char t6con				  @T6CON;

    Hi Dave,

    When can we expect the next release of Source Boost IDE?

    Will the the above device be included in the target device drop down menu?

    I have not yet down loaded the beta2 version.

    Regards

    Raghunathan.P


  9. Shree,

    The PWM output at the ccp pin is designed for 100hz and the two out of phase pulse generated in the ISR will have half the freq of the ccp pin ie.50hz.

    Dear sir, Please allow me to differ with you here. I think its the time which becomes half of the total ccp. So the freq would be double. Please correct me if I am wrong as I am a novoice.

     

    I still think that the CCPR1L's value must be half of the value of period register value in order to get a 50% duty cycle. Am I wrong? Further more I was just wondering whether the ECCP o/p keeps on running in background, allowing me to do any other jobs with my pic (like continously monitering the adc channel, making some ports high or low etc?)

    Thanks for your efforts and support

    Regards

    Shree

    Some times things defy our reasoning so I suggest u program a device & see the wave forms on an oscilloscope.

    Regards

    Raghunathan.P


  10. Hello,

    Thanks so much for being a help. I think I am getting a bit of it. But I didnt get the concept of the duty cycle and the total period. Considering your example, we have a 10ms period which would load the PR2 register with a value of 155 for 1MHz clock Freq and 1:16 prescaler for TMR2. Now as said by you the ON time of the pulse is determined by 10 bits of CCPR1L and CCP1CON<5:4>. If I consider that the pulse has duty cycle of 50% i.e. it remains ON for 5mS and off for 5mS, the formula stated for getting the values in the above 10bit yeilds a result 0f 312.5 (which is double of the PR2+1 value). I am confused about how can the ON time value be more then the total period value?

    Secondly I am trying to use a ECCP in half bridge mode. I wanted to know the exact coding method that is to be followed for implementing the ECCP in halfbridge. Have the interrupts to be used even if I want a fixed frequency (say 50% duty cycle) output on P1A and P1B pins, which would drive a MOSFET drive in Push-pull mode. Further more there is a deadband control register PWM1CON, the value entered in which would create a deadband of that value multiplied by 4Tosc. But nothing is mentioned about the value in CCPR1L register with this deadband. I mean say if I want a deadband of 1mS in 5mS ON time, i.e. the actaul ON time is only 4mS, then what should be the CCPR1L value? Should it be 312(for 5mS) as in above example or should it be calibareted for 4mS?

    I hope I am not making a mess and thanks for your efforts to explain the concept in detail. For sure I know much more now then before.

    Regards

    Shree

     

    Shree,

    The PWM output at the ccp pin is designed for 100hz and the two out of phase pulse generated in the ISR will have half the freq of the ccp pin ie.50hz.

    Now the pulse out at the ccp pin can have 0 to 100 % ON time by loading the ccpr1l & ccpr1h. This ccp pin pulse has to be ANDed with the 50hz pulse

    generated in the ISR. Then As the duty cycle changes from 0 to 100% in the ccp pin the 50hz pulse in ISR(RB0 & RB1) will vary from 0 to 50%.

    A graphical representation will make things better to understand. Try if u can figure out from the above information.

     

    Regards

    Raghunathan.P


  11. Hello Wizards,

    Sorry for being such a confused soul. But I am going berserk trying to implement a half bridge E-PWM module in order to drive 2 MOSFETS in push pull mode. I wrote the following code:

    #include <system.h>
    #pragma CLOCK_FREQ 8000000
    #pragma DATA _CONFIG, _WDT_OFF & _INTOSCIO & _CP_OFF & _PWRTE_ON & _IESO_OFF & _FCMEN_OFF & _CPD_OFF & _MCLRE_OFF & _BOR_ON
    
    void main()
    {
    //Setting up internal oscillator of 8MHz
    osccon.IRCF2=1;
    osccon.IRCF1=1;
    osccon.IRCF0=1;
    osccon.OSTS=0;
    osccon.SCS=0;
    
    trisc=0;
    portc=0;
    pr2=63; // 32uS=[PR2+1] * 4 * 125nS *1 [PWM Period= ((PR2+1)*4*Tosc*TMR2 Prescaler)]
    ccpr1l=128; //16uS=[DCB:DCB0] * 125nS *1 [Pulse Width=(CCPR1L:CCP1CON<5:4>) *Tosc* TMR2 Prescale] 
    ccp1con=0x8c; //Half Bridge Mode and PWM mode all pins active high
    pwm1con=4; //dead band Delay of 4*Tosc * n: 4*125nS*4= 2uS
    t2con=4; //TMR2 On with pre and post scaler 1:1
    while(1){;}
    }

    From the above program I am trying to get two complimentory pulses of 16uS (2uS deadband delay + 14uS ON) and 16uS off on pin P1A and P1B. Both are being used as active high. So total period on each pin is 32uS. My first confusion is if the period is total of ON time and OFF time, then how could the value loaded in PR2 registor is lesser then that in CCPR1L (In my case double as the duty cyle is 50%) and secondly is there something more to be added to the above code to acheive my task? I checked the O/P on the scope, but only P1A is showing some erraneous output. Guys I was never so much confused. Is this so hard to do?

    plz help me

    Thanks in advance

    Shree

     

    Hi Shree,

    I don't know about your code, but I can tell u how the PWM module works.

    First there are three important registers associated with it. they are

    1) tmr2 or timer2 register

    2) pr2 register also called the period register.

    3) ccpr1l & ccpr1h which holds the 10bit duty cycle value.

     

    a)PWM generates a square wave form output at the ccp pin.

    b)Any square wave form has an ON time & OFF time.

    c) The ON time is called the duty or duty cycle.

    d) One ON time plus one OFF time is called the period or T. Frequency of the wave form is f = 1 / T .

    e) The ON time is decided by the duty cycle value(10bit ccpril & ccp1con<5:4>) register.

    f) The Period or frequency is controlled by the pr2 value.

     

    How it works?

    Two comparators keep comparing the pr2 register value & duty cycle value with timer2(tmr2) value which is free running.

    When the tmr2 value equals pr2 value the ccp pin is made high & next when it reaches ccpr1l + ccp1con<5:4> value it makes the pin low.

    Also when tmr2 value equals pr2 value a flag is set & the tmr2 is reset to zero. You can enable the interrupt bit TMR2IE. You can try to

    change the duty cycle value in the ISR. You can also toggle your i/o pins in the ISR.

    Use this sample code on PIC16F72 or similar. Use external RC. R value is 10k & C value is 68pf. You can see the output in ccp pin. Also two out of phase

    50hz pulse in RB0 & RB1.

     

    #include <system.h>
    
    // Set clock frequency to 1MHz.
    
    #pragma CLOCK_FREQ 1000000
    
    //set configuration fuse.
    #pragma DATA _CONFIG, _RC_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF
    
    int duty_cycle;	//global variable
    
    /*Interrupt service routine (ISR).On timer2 interrupt, program 
     will jump to this code location.  */	
    void interrupt( void )
    {
    char pulse;
    /*generate two 50hz 180 degree out of phase pulses & externally
    AND it with the 100Hz pwm pin to get a modulated 50Hz to drive
    mosfets connected to a transformer in a push-pull configuration.
    A/D conversion of the the output voltage can act as feed back to
    adjust the duty-cycle ( not yet implemented in this code).
    */
    pulse = portb;  
    pulse.0 = ~ pulse.0;
    pulse.1 = ~ pulse.1;  
    portb = pulse;
    
    pir1.1=0;  //clear TMR2 to pr2 match interrupt flag
    }
    
    void load_duty_cycle(void)   
    {	
    ccpr1l.7 = duty_cycle.9;  
    ccpr1l.6 = duty_cycle.8;		   
    ccpr1l.5 = duty_cycle.7;  
    ccpr1l.4 = duty_cycle.6;  
    ccpr1l.3 = duty_cycle.5; 
    ccpr1l.2 = duty_cycle.4;  
    ccpr1l.1 = duty_cycle.3;  
    ccpr1l.0 = duty_cycle.2;  
    ccp1con.5 = duty_cycle.1;  
    ccp1con.4 = duty_cycle.0; 
    }
    
    
    
    // The main code configures the pwm registers
    void main()
    {
    trisa = 255;
      	trisb = 0;		 //configure port B as output
      	trisc = 0;	   // portc as out put
    portb = 1;		 //set port B to 1
    portc = 0;	   //clear portc
    
    
    
    // enable interrupts
    intcon.6=1;	 //enable peripheral interrupt	 
    intcon.7=1;	 //enable global interrupt
    
    pie1.1=1;	   //tmr2 to pr2 match interrupt
    
    //configure the ccp1con register to enable PWM module.
    
    /*ccpxm3:ccpxm0: mode select bits<3:0>
    11xx = for PWM mode.  
    */
    ccp1con=0b00001100; //
    
    
    //PWM period=[(PR2)+1]*4*Tosc*(TMR2 prescaler value)
    
    /*our pmw period is 10ms(100Hz),Tosc is 1/1000,000Hz & prescaler 
    is 16.For which PR2+1 works out to 156.25. Lets round it to 156 &
    make PR2 to 155. 
    */
    
    //load the period value into pr2 register.
    pr2 = 155;
    
    
    /*timer2 control register
    we have selected
    bit6-3...(0000) 1:1 for post scaler
    bit2.....(1) timer2 on
    bit1-0...(11) prescaler is 16
    */
    
    t2con = 0b00000111;  
    
    /*PWM duty cycle = (ccpr1l:ccp1con<5:4>)*Tosc*(TMR2 prescaler value)
    Here i have taken 2ms as an example value for duty cycle, Tosc & pre-
    scaler are same as above.We will get 10 bit values when we work with
    larger duty cycle but for our example we get the value as 125.
    */
    
    //load the duty cycle values 
    
    
    while( 1 )
    {
    int b0;
    for(b0=1;b0<563;b0++)
    {
    duty_cycle = b0;
    load_duty_cycle();
    delay_ms(9);
    }
    
    }
    }

     

    hope this helps

    Regards

    Raghunathan.P


  12. Are there functions in Sourceboost C Compiler for PWM?

     

    I think we don't have. You can make your own function. I have a sample code made long back. see if it can help u.

    Its made for PIC16F72, 1mhz RC clock.

    #include <system.h>
    
    // Set clock frequency to 1MHz.
    
    #pragma CLOCK_FREQ 1000000
    
    //set configuration fuse.
    #pragma DATA _CONFIG, _RC_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF
    
    int duty_cycle;	//global variable
    
    /*Interrupt service routine (ISR).On timer2 interrupt, program 
     will jump to this code location.  */	
    void interrupt( void )
    {
    char pulse;
    /*generate two 50hz 180 degree out of phase pulses & externally
    AND it with the 100Hz pwm pin to get a modulated 50Hz to drive
    mosfets connected to a transformer in a push-pull configuration.
    A/D conversion of the the output voltage can act as feed back to
    adjust the duty-cycle ( not yet implemented in this code).
    */
    pulse = portb;  
    pulse.0 = ~ pulse.0;
    pulse.1 = ~ pulse.1;  
    portb = pulse;
    
    pir1.1=0;  //clear TMR2 to pr2 match interrupt flag
    }
    
    void load_duty_cycle(void)   
    {	
    ccpr1l.7 = duty_cycle.9;  
    ccpr1l.6 = duty_cycle.8;		   
    ccpr1l.5 = duty_cycle.7;  
    ccpr1l.4 = duty_cycle.6;  
    ccpr1l.3 = duty_cycle.5; 
    ccpr1l.2 = duty_cycle.4;  
    ccpr1l.1 = duty_cycle.3;  
    ccpr1l.0 = duty_cycle.2;  
    ccp1con.5 = duty_cycle.1;  
    ccp1con.4 = duty_cycle.0; 
    }
    
    
    
    // The main code configures the pwm registers
    void main()
    {
    trisa = 255;
      	trisb = 0;		 //configure port B as output
      	trisc = 0;	   // portc as out put
    portb = 1;		 //set port B to 1
    portc = 0;	   //clear portc
    
    
    
    // enable interrupts
    intcon.6=1;	 //enable peripheral interrupt	 
    intcon.7=1;	 //enable global interrupt
    
    pie1.1=1;	   //tmr2 to pr2 match interrupt
    
    //configure the ccp1con register to enable PWM module.
    
    /*ccpxm3:ccpxm0: mode select bits<3:0>
    11xx = for PWM mode.  
    */
    ccp1con=0b00001100; //
    
    
    //PWM period=[(PR2)+1]*4*Tosc*(TMR2 prescaler value)
    
    /*our pmw period is 10ms(100Hz),Tosc is 1/1000,000Hz & prescaler 
    is 16.For which PR2+1 works out to 156.25. Lets round it to 156 &
    make PR2 to 155. 
    */
    
    //load the period value into pr2 register.
    pr2 = 155;
    
    
    /*timer2 control register
    we have selected
    bit6-3...(0000) 1:1 for post scaler
    bit2.....(1) timer2 on
    bit1-0...(11) prescaler is 16
    */
    
    t2con = 0b00000111;  
    
    /*PWM duty cycle = (ccpr1l:ccp1con<5:4>)*Tosc*(TMR2 prescaler value)
    Here i have taken 2ms as an example value for duty cycle, Tosc & pre-
    scaler are same as above.We will get 10 bit values when we work with
    larger duty cycle but for our example we get the value as 125.
    */
    
    //load the duty cycle values 
    
    
    while( 1 )
      {
       int b0;
       for(b0=1;b0<563;b0++)
      {
    	 duty_cycle = b0;
    	 load_duty_cycle();
    	 delay_ms(9);
       }
    
      }
    }

     

     

    Regards

    Raghunathan


  13. Me Too :rolleyes:

    Thank Jim, that is.

     

    The SourceBoost simulator needs a *LOT* of work, mostly in its plugins.

    It has the potential to be better than MPLAB Sim, but limitations like only one instance of each plugin (I have a hack for the LED Block one :)) mean I only use it for quick and dirty testing. It is not YET worth setting up a complicated set of plugin assignments, as one usually runs into some limitation before enough of the circuit is simulated.

     

    I often end up debugging in MPLAB Sim, (possibly influenced by my need to use MPLAB for the PICkit 2 debugger) and there one can 'fake' ADC support with a stimulus file. Once you are in MPLAB, one tends to do small edits andf rebuild without leaving it, but it tends to be somewhat unstable so I prefer the SourceBoost IDE.

     

    This is not the place for a SourceBoost IDE or compiler wishlist but if a plugin could be written to hook the simulator to a SPICE package or similar general purpose analog circuit simulator, Dave and Pavel would have a world-beating development environment. Owing to the open plugin interface its more likely to happen here than with the competitors.

     

    Well if they have a time/resource constraint, I would prefer they concentrate on getting a compiler for the 24bit device.

    Regards

    Raghunathan


  14. Hi Mark,

     

    Remember you are not passing the array but a pointer to it. So if your function modifies the array it is the original array that is being modified.

     

    Your function could have also have been declared using a pointer argument.

    signed long adc_decip (unsigned char *n)
    {
    signed long m;
    m = 0;
    m += *n++;
    m += *n++ * 10;
    m += *n++ * 100;
    m += *n++ * 1000;
    m += *n++ * 10000;
    if(adc_sign_digit==0)  
    {
     m = m*(-1);
    } 
    return m;  
    }

     

    BoostC does not let you specify the size of the array though in the function argument e.g. signed long adc_deci (unsigned char n[5]).

     

     

    Cheers

     

    Reynard

    Hi,

    There are some issues when u have your argument as pointer.

    declare the pointer as char *n

    as in the above case..

    signed long adc_deci ( char *n)
    {
    signed long m;
    m = 0;
    m += *n++;
    m += *n++ * 10;
    m += *n++ * 100;
    m += *n++ * 1000;
    m += *n++ * 10000;
    if(adc_sign_digit==0)  
    {
     m = m*(-1);
    } 
    return m;  
    }

    I have a doubt here???

    I think its ok to pass a string in the calling function & u need to check the null character as the terminator. Like the simple putc function

    void putc(unsigned char tx_char)
    {
    while(SSR0_TDRE == 0);
    TDR0 = tx_char;
    } 
    
    void puts(char *source)
    {
    while (*source != 0)   
    	putc(*source++);
    }
    void main()
    {
     while(1)
    {
      puts("raghu");
     }
    
    }

     

    But if u have a pointer as the argument in a function & u have a array to be passed in the call function, I think u need to write the call function this way

      adc_deci(&adc_bcd);   // in the first example
     puts(&adc_bcd);		 //2nd example

     

    Reynard, correct me if I am wrong.

    Regards

    Raghunathan.


  15. Can someone provide an example of a prototype using an array as an argument in a function, and an example function call?

     

    I cannot come up with the right syntax for my file to compile. I have tried using a pointer syntax as an argument, the array variable name, and a reference to the array. I am obviously missing something.

     

    In my reading I have seen that the compiler should translate the array argument into a pointer (if so defined). Is this the case with Boost?

     

    Thank you in advance,

     

    Mark

     

    bit adc_sign_digit;
    
    signed long adc_deci (unsigned char n[])
    {
    signed long m;
    m = 0;
    m += n[0];
    m += n[1] * 10;
    m += n[2] * 100;
    m += n[3] * 1000;
    m += n[4] * 10000;
    if(adc_sign_digit==0)  
    {
     m = m*(-1);
    } 
    return m;  
    }	  
    
    void main()
    {
    unsigned char adc_bcd[5];
    while(1)
     {
     if (portd.6 == 0)	 //if tare.
     {
    tare_value = adc_deci(adc_bcd);
     } 
    
      }
    }

     

    Regards

    Raghunathan


  16. Hi Shree,

     

    As you are using a 16F877A device, why not try using timer 2 and the preload register. That way you should be an interrupt every 250us and just let the timer free run and do its own thing. If you use the x4 post scaler the interrupts can arrive at 1ms intervals.

     

    Worth a try dude.

     

    Cheers

     

    Reynard

     

    Hi Reynard, Its not called preload register but period register. :unsure: timer2 is used for the pwm module & its value is compared with PR2 register and the duty cycle value( stored in a crazy way in the PIC). One can activate the interrupt for tmr2 PR2 match.

     

    Regards

    Raghu.


  17. A few years back we talked about the fact that TIMER 0 is not a good choice for a clock as there is an inherent error in reloading the counter. Since you are using a device that has newer timers (TIMER 2) you should use the new timer since you can set the compare value once and just recieve an interrupt at the desired rate. TIMER 0 is fine for keyboad debouncing but not for real-time clocks.

     

    I attached Clock.c and Clock.h that implements a clock using timer 2 that I used for a timelapse photo machine ( http://www.tedrossin.x10hosting.com/Electronics/Pic/Pic.html ) . The code includes a fine adjust to calibrate out crystal errors. The parts per million error on a cyrstal > 1MHz is usually pretty bad (20 to 50) such that your clock will lose or gain 10 to 20 seconds a day. A tuned 32KHz cyrstal connected to be a timer source is another way to get a good timebase. These cyrstals have very low PPM errors.

    This code has more than you want but should at least show you how to modify your code to use timer 2. If it is confusing, never mind as what you have may be good enough if you don't plan on leaving it running for more than a few days.

     

    If you want the ulitimate in accuracy on the cheap, go for sampling the power line (dropped down in voltage of course) to get a very reliable 60 or 50 Hz depending on where you live. The power companies control the beats per day to keep good old synchonous clock motors on the right time.

     

    I tried to search for the thread on this subject but could not find it. We had a blast a few year back about this issue.

     

    Hi Trossin,

    I disagree that you can't get accurate timing with tmr0. As of the crystal error is concerned you may be right. But every one uses a crystal.

    The sample code I had given in the thread "programming pic micro using boostc" is correct. I have checked it up using mplab stopwatch. And I have used it

    as a real time clock & it works fine. Build the program in mplab sim, make a break point in the first line in the ISR, reset the stop watch on the first interrupt

    & run it several times & you will see that the stop watch show 250us every time. The code tmr0 +=9 ; is all you need to add in the isr. Its a very simple code & it works.

    Shree, the error u might have got could be because u did'nt reset the timer at the first interrupt. The first interrupt will have a over head of the initial port setting & register config settings.

    Where u don't need to measure time intervals of 250us, Pommie's code is better because your code doesn't get interrupted often.

     

    Regards

    Raghunathan.


  18. Hi Sree,

    I didn't have time to go through your code. I think the eeprom read & write functions disable the interrupts while writing & reading. May be that could be one reason why your timing is not accurate.

    Regards

    Raghunathan.

    Hello Mr. Raghunathan,

    If you see the code, the interrupt and eeprom functions never occur toeghter. Besides there is always 1 second more in every minute. I dont know why.

    Regards

    Shree

    Well, if the eeprom write & read are not called while your timer/ interrupt is activated, there could be some other problem. you can probably check the timing on the mplab simulator using stop watch.

    Make your global variable dist as signed int. since you keep decrementing its value in the ISR. it may take negative value.

    use while(dist>0) or while(dist>-1)

    Regards

    Raghunathan.


  19. hi,

    for your serial receive program, u can use the space as the qualifier & start loading the other digits in an array. The size of the array depends on the data digits lenght. try placing full-load to the indicator determine the data length. I thought it should display 00001828 on the hyper.

    Regards

    Raghunathan.

    Currently I am using the STX command as a qualifier, then placing the data into my array after that. I really don't think that part is my issue now, but I will note that and try it if the crystal doesn't provide any improvements.

     

    Thank you for your suggestions.

     

    I would suggest u use the builtin function of the sourceboost to begin with. Some times I do face problem with data parsing. The data stream should be sent at the same rate( mind u this is not the baud rate). If there is a change in the data stream rate( say from 10characters/s to 20char/sec) then chances are there that some of the datas don't get received properly. For which I introduce a minimum delay between character equal to (10 * (1/baudrate)), assuming 10bit length data.

     

    Regards

    Raghunathan.

×
×
  • Create New...