12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Below is a part of a simple little program I've been experimenting with to generate a 'random' pause but of known maximum and minimum time period(average maximum wait about 12secs for the LED to flash as the program stands).

    The pause occurs randomly but because there are a maximum of 65535 'lenghts' if you will of a given time (be it clock cycles etc (I'm not sure how RANDOM works) it should be possible to my mind to work out how long the longest and shortest pause times will be when they occur (1 or 65535 lenghts) I think.

    So my question is this: How long does it take the PIC processor to calculate 1 lenght? At the moment the maximum and minimum pause times occur at 12secs max 1sec min.

    I hope this makes sense

    Code:
    X VAR WORD
    
    main:
    RANDOM x
    
    PAUSE X /4
    
    HIGH PORTA.2 
    PAUSE 1000
    low PORTA.2
    GOTO MAIN:
    Dave
    Last edited by LEDave; - 8th July 2010 at 00:22.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you setup a LCD or have the value of x sent to a terminal? I would think you should have at times a longer pause than 12 seconds??

    You may want to look at this also.
    http://www.picbasic.co.uk/forum/showthread.php?t=9350
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit,

    I've been working really hard on this. I've taken your idea of:

    Can you setup a LCD or have the value of x sent to a terminal?
    And done this:

    What I've done is change the original code to measure the time the LED is on rather than measure the time the program was 'PAUSED' because to my mind you can only use 'PULSIN' on a active pin. I've then tried to output that 'PULSIN' number using 'SEROUT2' to the Serial communicator.

    It nearly works I think, what it does is output a series of zeros, instead of the time in micro_secs. I suspect I've made an error here:

    Code:
    SEROUT2 PORTC.3, 16780, [DEC Z, 10 ,13] 'The measured RANDOM time sent to S/Communicator
    I think it could be the Decimal value of Z that's causing the problem (I hope) being as it should be measuring in blocks of Micro_secs.

    Here's the program, I feel I'm close, but am I?. If you could look the program over and give me a pointer that would be really appreciated. The chip is a 16F684.


    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00000000    'Set PORTA as OUTPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE OSC 4
    
    
    X VAR WORD  'Number between 1 & 65535
    Y var WORD  'Scaled down value of X 
    Z VAR BYTE  'The PAUSED value of Y in 10us Increments
    
    main:        
    RANDOM X            'Random number between 1 & 65535
    LET Y = (x /14)     'Scaled down value of X
    HIGH PORTA.2        'LED PORTA.2 lights up
    PAUSE Y             'LED on for time period of RAN_X_OVER_14
    PULSIN PORTA.2,1,Z  'The paused RANDOM time period stored in VAR Z
    SEROUT2 PORTC.3, 16780, [DEC Z, 10 ,13] 'The measured RANDOM time sent to S/Communicator
                                        'in 10us incremets
    low PORTA.2          'LED off
    GOTO MAIN:           'Do it all again
    Dave
    Last edited by LEDave; - 8th July 2010 at 21:47.

  4. #4
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Ah, have I got 'PULSIN' in the right place in the program? Might it be better in front of HIGH PORTA.2 ?

    Nope, still outputting zero's.

    The manual says of zero's:

    If the pulse edge never happens or the width of the pulse is too great to measure, Var is set to zero
    Now I'm thinking the pulse must happen because the LED lights and with a 'RANDOM' delay but could it be to big to measure?

    How big is too big to measure for a pulse?

    Dave
    Last edited by LEDave; - 8th July 2010 at 23:20.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    As far as I know PULSIN is for reading a pulse on a pin from the outside not a pulse from the inside.

    It has been a long day so maybe I am missing something... What exactly are you wanting to do?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,
    I see you've been making a lot of progress, good job!

    Remember that PBP executes one statement at the time. In this case you set the pin high, then you pause, then you start the pulsein statement which waits for a positive going signal which isn't coming since the pin is already set high so it times out and returns zero.

    On top of that, as Mackrackit says, PULSIN is meant to be used on pins configured as inputs, I'm not sure if it works like you have it.

    And, why do you need to measure it? Why not simply "print" the value returned by the RANDOM command? I mean PAUSE works with units of ms if RANDOM returns 100 you divide that by 14 and get 7 so you'll get a pause of 7ms, if RANDOM returns 34567 you divide that by 14 and you'll get 2469ms pause. I don't see the point in trying to measure that but if you really need to do that then look into using one of the PICs hardware timers. Reset it, set the pin high and start the timer. Pause x, set the pin low, stop the timer and read its value.

    /Henrik.

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    Sorry for the late reply.

    I see you've been making a lot of progress, good job!
    That'll be down to mackrackit, yourself and a few others, thanks for sticking with me, it's very much appreciated.

    Remember that PBP executes one statement at the time. In this case you set the pin high, then you pause, then you start the pulsein statement which waits for a positive going signal which isn't coming since the pin is already set high so it times out and returns zero.
    I was running the program through my mind as I was going of to sleep last night and realised
    just that.

    On top of that, as Mackrackit says, PULSIN is meant to be used on pins configured as inputs, I'm not sure if it works like you have it.
    Another mistake, I got the PULSIN idea into my mind and rushed to write some code and overlooked setting the the REGISTER pin to INPUT.Good practice would be to set the I/O REGISTER then start writing code, I'll try and stick with that from now on.

    And, why do you need to measure it? Why not simply "print" the value returned by the RANDOM command?
    Another gap in my knowledge base I'm afraid, I didn't know you could 'print' the value.

    PAUSE works with units of ms if RANDOM returns 100 you divide that by 14 and get 7 so you'll get a pause of 7ms, if RANDOM returns 34567 you divide that by 14 and you'll get 2469ms pause.
    Spot on Henrik, just what I needed to know.

    I'm trying to write a program for a project which must have a RANDOM delay of zero to three seconds.

    So how about this:

    65535 / 21.845 gives 3000ms as a Maximum value. Any number generated will be lower than 65535 therefore shorter than 3 seconds!


    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00000000    'Set PORTA as OUTPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE OSC 4
    
    
    X VAR WORD  'Number between 1 & 65535
    Y var WORD  'Scaled down value of X 
    Z VAR BYTE  'The PAUSED value in 10us Increments
    
    main:        
    RANDOM X            'Random number between 1 & 65535
    LET Y = (x /22)     'Scaled down value of X
    PAUSE Y             'LED on for time period of RAN_X_OVER_22
    HIGH PORTA.2        'LED PORTA.2 lights up
    PAUSE 500
    low PORTA.2          'LED off
    GOTO MAIN:           'Do it all again
    Dave
    Last edited by LEDave; - 9th July 2010 at 13:33.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts