Author Topic: CCP module on PIC controller?  (Read 4204 times)

0 Members and 1 Guest are viewing this topic.

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
CCP module on PIC controller?
« on: April 18, 2015, 07:55:28 pm »
I want to decode the DCC protocol used for model railroading with a pic microcontroller. I start this project with an experiment: a 15khz square wave is connected to the CCP2 input pin. The CCP module should capture the values of TMR1 on each rising edge and display that value on the lcd.

I know the lcd is connected an configured correctly, but i don't see a value appearing on it. I think the interrupt is not fired and it's likely that i forgot to enable something, but can't find what that might be.





Code: [Select]
;-------------------------------------------------------------------------------
;programma
;Controller = PIC 16F886
;-------------------------------------------------------------------------------
include 16f886
;Alle mogelijke 'fuses' voor een 16F887
;8MHz intern
pragma target OSC INTOSC_CLKOUT
pragma target clock 8_000_000        -- oscillator frequency
pragma target WDT   disabled           -- WDT off
pragma target LVP  disabled           -- no low voltage programming
pragma target PWRTE DISABLED          -- power-up timer enable bit
pragma target MCLR  Internal          -- re3/mclr pin function select bit

pragma target CPD   DISABLED          -- data code protection bit
pragma target BROWNOUT DISABLED       -- brown out reset selection bits
pragma target IESO  DISABLED          -- internal external switchover bit
pragma target FCMEN DISABLED          -- fail-safe clock monitor enabled bit
pragma target DEBUG DISABLED          -- in-circuit debugger mode bit

OSCCON_IRCF=0b111 -- set oscillator to full speed 8 Mhz (standard 4 Mhz)

-------------------------------------------------------------------------------
;lcd setup
-------------------------------------------------------------------------------

const byte LCD_ROWS    =  2            --LCD with 2 lines
const byte LCD_CHARS   =  16           --and 16 characters per line

alias     lcd_en       is pin_b5       --LCD EN
alias     lcd_rs       is pin_b4      --LCD RS
pin_b5_direction       = output        --Beiden
pin_b4_direction       = output        --als uitgangen

alias lcd_dataport  is  porta_low      --4 databits
porta_low_direction = output           --eveneens als uitgang

;De bibliotheek met LCD routines laden
include lcd_hd44780_4
;Gebruik maken van bestaande routines om iets op het LCD tre laten verschijnen
include print
;Getallen geformatteerd weergeven op het LCD met ingebouwde functies uit de
;format bibliotheek
include format
;En het LCDinitialiseren
lcd_init()

--------------------------------------------------------------------------------
;setup registers for capture on ccp2
--------------------------------------------------------------------------------
INTCON_GIE=true  -- enable interrupts
INTCON_PEIE=true  -- enable peripheral interrupts

PIE2_CCP2IE=true; --enable ccp2 module interrupt
T1CON_TMR1ON=on   --enable timer1 as timer, no prescaler
CCP2CON=5;   --set ccp module to interrupt on each rising edge

alias dccinput is pin_ccp2  -- input pin for ccp module
pin_ccp2_direction=input


--------------------------------------------------------------------------------
procedure isr is
pragma interrupt

lcd_cursor_position(0,0)
print_byte_dec(lcd,ccpr2h)
lcd_cursor_position(1,0)
print_byte_dec(lcd,ccpr2l)


PIR2_CCP2IF=false

end procedure
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2340
Re: CCP module on PIC controller?
« Reply #1 on: April 18, 2015, 08:18:14 pm »
Is that all the code? What does it *do* when it is not in the interrupt ?
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
Re: CCP module on PIC controller?
« Reply #2 on: April 18, 2015, 10:13:07 pm »
idiot I am! Wrote the code for CCP2, but connected the square wave to CCP1 input |O


Now it's working, but not the "right" values... I expect to approximately 120, but that's not the case here....
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2340
Re: CCP module on PIC controller?
« Reply #3 on: April 18, 2015, 11:07:39 pm »
Wrote the code for CCP2, but connected the square wave to CCP1 input
:) I don't think you can blame the PIC for that one, (although I've often tried)  ;)
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
Re: CCP module on PIC controller?
« Reply #4 on: April 19, 2015, 09:58:16 pm »
I'm not an expert in programming, but want to learn it. Today i tried to detect the preamble sequence in a DCC-packet. But there's a problem.... I expect to see "preamble" on the display, but doesn't detect that sequence and so nothing appears on the display. (explanation is in comments between code)

http://www.treinbaanrian.be/elektronica/20150419_decoder.htm

Who knows what's going wrong?
 

Offline BloodyCactus

  • Frequent Contributor
  • **
  • Posts: 484
  • Country: us
    • Kråketær
Re: CCP module on PIC controller?
« Reply #5 on: April 20, 2015, 06:15:08 pm »
have you looked at the arduino dcc library? the opendcc project? there are lots of arduino dcc code around that you can use to check against your own work and see working code vs your code vs what you expect to see it doing etc.
-- Aussie living in the USA --
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->