I highly doubt that. I don't know how you're testing it, but if that's the case things are seriously broken.IF PORTC.4=1
or
IF PORTC.4=0
makes corresponding pin high or low?
You likely have some other issue.
I highly doubt that. I don't know how you're testing it, but if that's the case things are seriously broken.IF PORTC.4=1
or
IF PORTC.4=0
makes corresponding pin high or low?
You likely have some other issue.
The IF statement per se should not and I'm pretty sure does not twiddle the pin but if what you you're doing is somehing like......and there happens to be analog functions on the pins which you haven't disabled then the actual state of PortC.4 isn't read correctly and you're getting into the classic RMW issue where the "invalid" state of PortC.4 is being written back to PortC.4 when the write operation to PortC.1 occurs but without seeing the rest of the code it's hard to say for sure.Code:If PortC.4 = 0 THEN PortC.1 = 1 ENDIF
/Henrik.
Here is the complete code:
I have source of signal (chip with name grinded off, but holtek logo is recognizable), which is connected directly to PORTC.4. Also, scope is connected to same pin.Code:Include "modedefs.bas" ' Include serial modes TRISA = %11111111 ' Set PORTA to all input TRISC = %00000000 ' Sets all PortB pins to output ADCON1 = %10000101 ' Set PORTA analog and right justify result ADCON0=%00000000 low portc.4 low portc.5 X VAR PORTC.4 DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 4 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 0 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 1 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 1500 DEFINE LCD_DATAUS 44 DEFINE OSC 4 lcdout "test 2" PAUSE 500 LABEL VAR WORD DROEBITI VAR WORD taki: if portc.4=0 then COUNT PORTC.4, 60, LABEL endif if label=0 then goto taki endif LCDOUT $FE,$c0, DEC(LABEL), " " GOTO TAKI
As long as I introduce the statement "if portc.4=0 then"
If it is "=0" then pin is sunk to ground, so no pulses can be detected, and nothing can be seen on scope. If it is "=1", then pin gets driven high, and no pulses can be seen with scope or read too.
Chip is 16F870.
Is there something strange here?Code:TRISA = %11111111 ' Set PORTA to all input TRISC = %00000000 ' Sets all PortB pins to output ADCON1 = %10000101 ' Set PORTA analog and right justify result ADCON0=%00000000 low portc.4 low portc.5
Last edited by pedja089; - 8th July 2016 at 21:42.
Easy! It’s giving you a wider pulse duration at the start to qualify the incoming data.
From there you only need to sample 32 times at the correct interval.
So look for that, then read it in with a 32 step loop.
Of course, better ways than reading into a 32 byte array, but quickest.Code:bitcode var byte[32] count var byte pulseduration var byte pulseduration = time from peak to peak for count = 0 to 31 bitcode[count] = inputpin pause pulseduration next count
You're omitting an important thing - MCU has own clock, wastes different time on program execution, but incoming data is sent async, so it can't wait for MCU to become ready, so my guess, how it all should work, is as follows:
As pulse arrives, we start recording it as fast as possible, after pulse sequence finished, we just count numbers of 1's and 0's recorded, and based on that, decide what to do with decoded data. Considering total sequence duration and speed, I guess, external sram or eeprom might be needed?
That depends. You didn’t display the duration.
If it’s several uS duration pulses, the falling edge of the first longer pulse is the place to mark time,
then waste half a pulse duration before the for-next loop. If you can roughly synchronise from the first pulse (which is what it’s for),
it takes time for the two clocks to drift apart.
If you were to sample bits as fast as you can, you’d still want to do that from the falling edge of the first pulse.
for comparison I came up with this , oddly it uses mode code space
Code:'**************************************************************** '* Name : deMODULATOR.BAS * '* Author : richard * '* Notice : Copyright (c) 2016 * '* : All Rights Reserved * '* Date : 5/29/2016 * '* Version : 1.0 * '* Notes : decodes missing pulse encoded data stream A.5 * '* : 16F1825 * '**************************************************************** #CONFIG __config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF __config _CONFIG2, _PLLEN_ON & _LVP_OFF #ENDCONFIG OSCCON=$70 DEFINE OSC 32 ' PIC 16F1825 TRISA = %111110 ' Make somepins Input trisc = %111100 ;Make some pins Input ANSELA=0 ANSELC=0 led var latc.0 ;DEBUG led2 var latc.1 ;DEBUG demod var porta.5 ;demod in X VAR byte darta VAR byte[4] counter var word dm_state VAR byte lata.0=1 ;DEBUG clear led=0 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 pause 2000 Debug "Start",13 ,10 DEFINE PULSIN_MAX 9000 main: select case dm_state case 0 PULSIN demod, 0, counter if counter > 7800 then dm_state=1 x=0 endif case 1 pir1.1=0 tmr2=0 t2con=7 while demod : wend if pir1.1 | (tmr2 < 220) then dm_state=0 else dm_state=2 tmr2=0 endif case 2 while !demod : wend t2con=0 if pir1.1 then dm_state=0 led=1 endif if tmr2 < 150 then darta.0[x]=0 else darta.0[x]=1 endif tmr2=0 x=x+1 if x >31 then dm_state=3 else while demod : wend t2con=7 endif case 3 led2=1 ;DEBUG ' Debug 13 ,10 ,hex2 darta[3] ,hex2 darta[2],hex2 darta[1],hex2 darta[0] ;DEBUG Debug 13 ,10 ,bin8 darta[3],bin8 darta[2],bin8 darta[1],bin8 darta[0] ;DEBUG pause 200 led2=0 ;DEBUG dm_state=0 end select goto main
Last edited by richard; - 10th October 2016 at 10:38. Reason: left a line out
Warning I'm not a teacher
the 1ms was just test, I used it to check MCU speed, whenever OSCCON and DEFINE OSC were correct, later it was removed.
I have Henrik's code running, I connect it to actual hardware, and width of large pulse, which should be 9000us, measured only 600 ?
I've copied all code from post #35, including timings.
http://www.picbasic.co.uk/forum/show...165#post138165
then you are doing something wrong ,plus you said in previous posts the pulse was 9900uS it makes a difference . whats correct ?I have Henrik's code running, I connect it to actual hardware, and width of large pulse, which should be 9000us, measured only 600 ?
your looking more scatterlogical than my exwife
Warning I'm not a teacher
haha, no, I'm not blond
Just I'm multi-tasking very hard.
9000, 9900, it was just typo, exact timings are given on the previous page. I don't know what I'm doing wrong, since code is Henrik's. As I said, I verified MCU speed and OSC settings, and they are all correct. Pulse timings are also correct, verified using two different scopes. this is only what I can do.
Bookmarks