Who sees my stupid mistake?


+ Reply to Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    57

    Default Who sees my stupid mistake?

    Hello,

    After not having used picbasic for a couple of years, I decided to create some code to produce MIDI information.
    The intended use is to have five buttons to control a DAW.
    The code compiles without a problem, but I don't get any MIDI (31.250 Baud) output. Xtal = 20 MHz, PIC = 16F628.
    I think I made an obvious mistake, but I don't see what it could be...

    Code:
    '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    '* MIDI Remote for Reaper            20 MHz resonator (HS)          
    '* PIC16F628                         Watchdog timer OFF              
    '* PORTA.0 = Output                                                  
    '* PORTB.0 = Rewind                                                  
    '* PORTB.1 = FastFwd.                                               
    '* PORTB.2 = Stop                                                   
    '* PORTB.3 = Play                                                   
    '* PORTB.4 = Record                                                 
    '* PORTB.5 = Switch between: Stop / Stop + Save
    '* Version 1.0                                      
    '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    
    TRISB= %00111111                                 ' PORTB.6/7=Output 0..5=Input
    CMCON =  7                                             ' Digitale mode
    DEFINE OSC 20                                        ' 20 MHZ OSC.
    
    Progstart: 
    
      if PORTB.0 = 1 then 
        Serout2 PORTB.7, 16384+12, [144, 44, 127]    ' Rewind
      endif  
      if PORTB.1 = 1 then 
        Serout2 PORTB.7, 16384+12, [144, 46, 127]    ' Fast Fwd.
      endif  
      if PORTB.2 = 1 then 
        if PORTB.5 = 0 then                          ' Normal STOP mode
          Serout2 PORTB.7, 16384+12, [144, 48, 127]  ' Stop
        else
          Serout2 PORTB.7, 16384+12, [144, 54, 127]  ' Stop + Save
        endif    
      endif  
      if PORTB.3 = 1 then 
        Serout2 PORTB.7, 16384+3313, [144, 50, 127]  ' Play  
      endif  
      if PORTB.4 = 1 then 
        Serout2 PORTB.7, 16384+3313, [144, 52, 127]  ' Record
      endif  
    
    Debounce:
      Pause 20                                          ' ? shorter ?
      If (PORTB.0=1) or (PORTB.1=1) or (PORTB.2=1) or (PORTB.3=1) or (PORTB.4=1) then
        goto Debounce                                ' Button still pressed?
      endif  
      Goto Progstart

  2. #2
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    I forgot to mention that there are resistors to ground (to keep the input 'low' when no button is pressed) and that the buttons switch to the +5 Volts.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,531


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    16384+12 seems correct for (inverted) 31250 but should it BE inverted and why 16384+3313? (I don't know MIDI...)

    Can you do a standard baudrate like 9600 and verify that data is coming out by using a terminal program?

    The 16F628 does have UART so HSEROUT will work with it. I'd try that but you might need to invert the signal externally.

  4. #4
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    The 16384+12 is correct, I have used that before.
    The calculation is: (1.000.000/Baudrate) - 20 , so 1.000.000 / 31250 = 32 -20 = 12.
    For inverted output set bit 14, = 16384.
    But even with a different baudrate I don't get any output.

    I did a quick test to trace the problem.
    With this code, nothing 'toggles':

    Code:
    Progstart: 
      if PORTB.0 = 1 then 
        Toggle PORTB.6
      endif  
    
    Debounce:
      Pause 20                                       ' ? shorter ?
      If PORTB.0=1 then
        goto Debounce                                ' Button still pressed?
      endif  
      Goto Progstart
    So I suspect the problem is in the line (and similar lines)
    Code:
      If PORTB.0=1 then
    Although I don't see what could be wrong with this...

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,659


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    If I don't touch programming for a while, I start with blinking a LED to make sure I have the basics working right (config, circuit, programming, etc).
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,659


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    Quote Originally Posted by RuudNL View Post
    ...
    If PORTB.0=1
    ...

    You're assuming it can read port B properly.

    I'd start even easier, just blink a LED, nothing else, then build from that.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Who sees my stupid mistake?

    So nobody can spot a mistake in my sample code?
    Strange, because this line is handled correctly:
    Code:
    If (PORTB.0=1) or (PORTB.1=1) or (PORTB.2=1) or (PORTB.3=1) or (PORTB.4=1) then
    .....

Similar Threads

  1. I don't understand my mistake
    By kik1kou in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st January 2015, 12:56
  2. Stupid simple question.....
    By chien_fu in forum mel PIC BASIC
    Replies: 18
    Last Post: - 23rd February 2010, 13:21
  3. Stupid question about LCDOUT
    By Glenn in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 7th October 2008, 21:37
  4. SERIN2 – SEROUT2 and Manchester mistake.
    By RCtech in forum Serial
    Replies: 8
    Last Post: - 4th September 2007, 22:55
  5. Stupid question
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th July 2007, 05:47

Members who have read this thread : 13

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