+ Reply to Thread
Page 10 of 12
First ... 6 7 8 9 10 11 12 Last
Results 136 to 150 of 166

Thread: C18 Questions

  1. #136
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    sorry, what do you mean by doing it using hardware? You mean like the capture compare module on the chip?
    Last edited by Triode; 6th September 2009 at 10:58 PM.
    -Paul


  2. #137
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,464
    Blog Entries
    11

    Default

    Quote Originally Posted by Triode View Post
    sorry, what do you mean by doing it using hardware? You mean like the capture compare module on the chip?
    Not sure I have never done this.
    There must be an example of this somewhere.
    3v0
    Last edited by 3v0; 6th September 2009 at 11:36 PM.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  3. #138
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    Yeah, I could set it up in software, or at least I know how I'd try, but I have no idea how to set up hardware capture.

    I'm looking at this document about it now.
    Capture/Compare/PWM
    and also this
    Pic Midrange Libraries Reference Manual
    -Paul

  4. #139
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,464
    Blog Entries
    11

    Default

    I found an appnote that should make you day.

    PICmicro CCP and ECCP Tips ‘n Tricks

    http://ww1.microchip.com/downloads/e...Doc/41214a.pdf

    Check out
    TIP #3 Measuring Pulse Width
    1. Configure control bits CCPxM3:CCPxM0
    (CCPxCON<3:0>) to capture every rising
    edge of the waveform.
    2. Configure Timer1 prescaler so that Timer1 will
    run WMAX without overflowing.
    3. Enable the CCP interrupt (CCPxIE bit).
    4. When CCP interrupt occurs, save the captured
    timer value (t1) and reconfigure control bits to
    capture every falling edge.
    5. When CCP interrupt occurs again, subtract
    saved value (t1) from current captured value
    (t2) – this result is the pulse width (W).
    6. Reconfigure control bits to capture the next
    rising edge and start process all over again
    (repeat steps 3 through 6).
    I would try to break the task up into 3 states and some ISR code. I used letters for the states to prevent confusion with the above steps.

    (state A) step 1-2 seq=B
    (state B) step 3, block on ISR finding value, seq=C
    step 4 and 5 will be done in the ISR
    (state C) copy or process W value, seq=A

    The thing that get a bit more difficult is that you now have another source of interrupts. Also within the timer1 ISR code you need to know if you have just found a leading or a trailing edge.

    My suggestion is to get the method working as simple example then break it up into states.

    If it was easy everybody would do it

    3v0
    Last edited by 3v0; 7th September 2009 at 04:37 AM.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  5. #140
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    Well hey! that pretty much hands it to me. I'm just getting my PWM source going, and this should really speed things along!
    -Paul

  6. #141
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,464
    Blog Entries
    11

    Default

    I added some text to the previous post.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  7. #142
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    It will indeed still take a while, I just meant it will help me get past the current snag. The final goal of making a device plug into two ports of a servo receiver and control two motors in two directions is a way off. But one by one I'm knocking parts of it off the list.
    -Paul

  8. #143
    Wond3rboy Okay
    Join Date
    Jun 2008
    Location
    Hyderabad,Pakistan
    Posts
    473
    Blog Entries
    2

    Default Sending an array of data(not string)

    Hi i want to send a array of data through the serial port but when i try to use a pointer to address the array and then write

    at start of program tempptr=tempdata;


    then

    putcUSART(*tempptr);
    tempptr++;

    it gives a syntax error.

    On the other hand tempdata[counter] works fine.
    Syed

  9. #144
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,812

    Default

    Quote Originally Posted by Wond3rboy View Post
    Hi i want to send a array of data through the serial port but when i try to use a pointer to address the array and then write

    at start of program tempptr=tempdata;


    then

    putcUSART(*tempptr);
    tempptr++;

    it gives a syntax error.

    On the other hand tempdata[counter] works fine.
    If you're using BoostC then it doesn't support ROM based pointers. You have to use the Var[offset] type of indexing.

    Mike.

  10. #145
    Wond3rboy Okay
    Join Date
    Jun 2008
    Location
    Hyderabad,Pakistan
    Posts
    473
    Blog Entries
    2

    Default

    I am using C18 and wanted to use a pointer to index an array(a very very simple application).But i got errors so i used the conventional method.My question is

    Can you index a numeric array using the built in functions of the USART.I tried and i got errors..am i doing it incorrectly?

    PS: I have already done it the other way but wanted to clear my self about the abilities of C18.
    Syed

  11. #146
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,812

    Default

    I would guess that the function expects a ram based variable and wont work with a rom pointer, try,
    Code:
    static rom char HW[]="Hello World!";
    rom char *P;
    char i;
    
    P=HW;           // or P=&HW[0];
    while(*P){
        i=*P++;
        putcUSART(i);
    }
    
    Mike.
    Last edited by Pommie; 7th September 2009 at 07:03 AM. Reason: corrected case.

  12. #147
    Wond3rboy Okay
    Join Date
    Jun 2008
    Location
    Hyderabad,Pakistan
    Posts
    473
    Blog Entries
    2

    Default

    I am using a RAM Array already, but since it does not accept a ram array pointer so guess it was not working.I would rather use the conventional array indexing approach since my application allows it.The code you provide works.Thanks for you reply.
    Syed

  13. #148
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    Alright, I coded a C18 version of what 3v0 posted above in post #139. The code is below, I have just included the part for the CCP setup, the interrupt and the timer setup:

    configuration
    Code:
    	//configure timer1
    	OpenTimer1(0b10010101);
    	
    	PIE1bits.TMR1IE = 1; //periferial interupt register, 1 = timer 1 interupt enabled
    	PIR1bits.TMR1IF = 0; //clears the timer 1 interupt flag
    
    	//configure CCP1 for capture, rising edge
    	CCP1CON = 0b0000101;
    
    code withen interrupt function
    Code:
    	//ccp interrupt
    	if(PIR1bits.CCP1IF == 1)
    	{	
    		if(PWM1Edge == 1)//if detecting rising
    		{	
    			interrupttest3++;
    			
    			PWM1RiseTime = CCPR1;//save the low timer value for the rise time
    			CCP1CON = 0b0000100;//switch to detect falling edge
    			PWM1Edge = 0;//switch to indicate falling edge is next
    		}
    		else //detecting falling
    		{
    			interrupttest2++;
    
    			PWM1Width = CCPR1 - PWM1RiseTime;
    			CCP1CON = 0b0000101;//switch to detect rising edge
    			PWM1Edge = 1;//switch to indicate rising edge is next
    		}
    		
    		interrupttest1++;
    		PIR1bits.CCP1IF = 0; //clear the flag
    	}
    }
    
    So far it is working ok. The value I get ranges from 178 with the knob all the way in one direction to 143 all the way in the other, at a given position the value varies by as much as 9, but that variance increases towards the extremes, varying only by 3 in the neutral center position.

    I'm looking for suggestions on how this could be improved. As I am not very good with timers, and CCP1 depends on timer1, I suspect that I could improve the settings there to get higher resolution. Would the resolution go up as the prescaler goes down or vice versa? Part of my concern is that I haven't really followed this step "Configure Timer1 prescaler so that Timer1 will run WMAX without overflowing." since I don't really understand prescalers. So, I'll need to read up on them and get that part fine tuned.

    Any other suggestions on how this could be improved would be appreciated.

    details: Im using a traxas 2215 receiver at 27mhz, it is connected to the 3 pin port of my junebug (RB3,UV5,GND)
    Last edited by Triode; 17th September 2009 at 05:27 AM.
    -Paul

  14. #149
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,812

    Default

    You don't mention the speed of your chip but as it's a Junebug I assume you set it to 8MHz. If this is the case then I would set the prescaler to 2 so each timer 1 count = 1uS. This will mean that typical servo pulses should give you readings from 1000(1mS) to 2000(2mS). The prescaler is how much to divide the clock by before feeding it to timer 1 - it is already divided by 4 and so is effectively 2MHz.

    Mike.

  15. #150
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    Yes, I'm using the 18F1320 on the junebug. I don't remember setting the speed of the chip, but I'll check on that.

    I also have a question about debug mode. So far it seems as if it runs at full speed, if I have a LED set to blink every 1000mS, it seems to keep blinking every second weather I'm in debug mode or not, and the capture timing seems correct too. Does debug run at full speed?
    -Paul

+ Reply to Thread
Page 10 of 12
First ... 6 7 8 9 10 11 12 Last

Similar Threads

  1. A few questions
    By erosennin in forum Feedback/Comments
    Replies: 24
    Latest: 28th November 2007, 11:08 PM
  2. 2 questions
    By juan123 in forum Electronic Projects Design/Ideas/Reviews
    Replies: 5
    Latest: 27th September 2007, 02:46 AM
  3. A few questions.
    By Marks256 in forum General Electronics Chat
    Replies: 55
    Latest: 5th August 2006, 10:49 PM
  4. few questions
    By Victor Frankenstein in forum General Electronics Chat
    Replies: 13
    Latest: 5th July 2005, 06:29 PM
  5. Questions?
    By Philipc in forum Electronic Projects Design/Ideas/Reviews
    Replies: 4
    Latest: 7th August 2003, 06:18 PM

Tags for this Thread