Which chip do i use?


Closed Thread
Results 1 to 40 of 78

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Solved the oscillator problem.

    "DEFINE osc 16" doesnt work
    "DEFINE OSC 16" does work

    Serial still not working but i have a feeling thats something simple.

    Ive tried 2 things from Mister-e's calculator
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 9600 Baud @ 16MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Code:
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 25  ' 9600 Baud @ 16MHz, 0.16%
    I have also added this code
    Code:
    loop:
    if pir1.5=1 then
              newbyte=rcreg
              high portb.0
              pause 100
              low portb.0
    endif
    goto loop
    when any serial data comes in that should make the LED flash but its not doing. I think this might be to do with the circuit itself (currently thinking outside of the box. Using breadboard instead). Ill try and solve that tomoz. For now though i really am going to bed :P Ill let you know how it goes tomoz

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    if you don't use any HSERIN/HSEROUT you use the second methode, unless you use the DEFINE method.

    this one work here
    Code:
            @   __CONFIG _HS_OSC & _LVP_OFF
            DEFINE OSC 20
            
            PORTB=0
            TRISB = %00000010
            RCSTA = $90 ' Enable serial port & continuous receive
            TXSTA = $24 ' Enable transmit, BRGH = 1
            SPBRG = 129 ' 9600 Baud @ 20MHz, 0.16%
                
            PIE1.5 = 1  ' Enable USART interrupt
            
    
    start:
            if PIR1.5 = 1 THEN  ' RCIF FULL?
                    PORTB.0=1
                    PAUSE 200
                    PORTB.0=0
                    WHILE PIR1.5 
                        TXREG=RCREG ' send it back to the pc
                                    ' utill USART buffer is empty
                        wend
                    
                    if RCSTA.1=1 THEN  ' ANY Overrun?
                        RCSTA.4=0      '  YES clear it
                        RCSTA.4=1      '
                        ENDIF
                        
                    endif
                    
            goto start
    just change DEFINE OSC, TXSTA and SPBRG to suite your requirement. Make sure you have a RS232 inverter (MAX232 or else) between your PC and your PIC.

    And YES the DEFINE's have to be in capital letter, unless it will never work.
    Last edited by mister_e; - 29th November 2007 at 14:24.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Thanx for the code. Just a few questions on it. "@ __CONFIG _HS_OSC & _LVP_OFF" causes an error.

    Why do i need an "RS232 inverter"? Serial works fine through serin2. I think Matt did use one because theres some extra stuff on the serial input but i wasnt sure what it was for. It appears to be an optoisolator and a diode

  4. #4
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Im finally getting somewhere with it. Ive got it to recognise when serial data is being sent and ive got it to fade the bulb out using the sync with the zero crossing. There is still a problem that remains. The serial data that comes in is being currupted. I have a feeling this is to do with that RS232 inverter you mentioned.

    Ive seen examples on the net saying serin2 can use inverted and non-inverted serial. Can i use non-inverted here too? At the moment i have a 100K resistor from VSS to RX and a 330ohm resistor from the serial port to RX. That is how i normally do it and it works with serin2.

    I used your code example to echo the input back to the PC. I sent it numbers from 1 to 100 but it replied with completely diff numbers. They appear to be random but they arnt because if i send the same value twice i get the same value back twice.

    I think im so close now. PWM is working and i can program the chip to make the lights fade out Its just sorting this last serial problem out and hopefully i can start work on the real program

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The PIC USART use TRUE mode, and there's no way to use INVERTED mode for that PIC, hence why you need a max232 or transistor or else inverter.... also why you have strange results on your PC when you echo the data.

    st a few questions on it. "@ __CONFIG _HS_OSC & _LVP_OFF" causes an error.
    You must use MPASM to use this line, or change it to PM requirement. Even if you're using MPASM, it may return an error (overwriting previous address plah plah).

    Have a look at the following for more info about Configuration Fuses.

    Presetting Configuration Fuses (PIC Defines) into your Program

    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Yes. That overwrite thing was the error i got. I have got MPASM turned on. I thought it didnt like it.

    What is the cheapest option for the 232 inverter? Ive had a look for max232 in rapid and they range from a few pence to a few pounds but i dont completely understand which type i need. I have a single serial input that must go to 2 PIC chips.

    Matt used a MOC8102 but rapid dont sell those. Once i know what i need for this im gonna order the parts straight away. Im sure everything else is sorted. Just the serial to go.

    Ive connected a wire from Matts box into the pic so i can use his circuit for the serial while im testing so i can get on and program the chip. I do have a small question about the program. Its still fading in upto about 40% then 40-60% are all the same brightness and 60-100% work as expected. Do i just alter the timings to compensate?

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Wow. This thing runs so fast I managed to send commands from the PC so fast that i almost managed PWM (it was flickery tho cos the PC isnt sync'd)

    Ive got a good idea of the code that im gonna write now so ill sort that tomoz. I just need to know about the serial inverter now and i can get the parts ordered and finish designing the PCB

Similar Threads

  1. Trouble with PIC16F88 (chip hangs up)
    By nobner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th January 2009, 09:23
  2. Camera with PIC chip
    By The Master in forum Off Topic
    Replies: 5
    Last Post: - 1st July 2008, 14:28
  3. More info on L4620 liquid sensor chip
    By Nicmus in forum Documentation
    Replies: 4
    Last Post: - 1st June 2008, 23:03
  4. TV Display Chip
    By zadok in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 17th April 2008, 22:17
  5. chip selection aid
    By PICMAN in forum General
    Replies: 4
    Last Post: - 21st February 2005, 18: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