surely a candidate for timer1 and gate control
surely a candidate for timer1 and gate control
Warning I'm not a teacher
Currently I have LCD connected, for debugging purposes, but in final device, I will have no LCD.
So this is how initial things should work, as I see it:
1. We sent interrupt on rising edge of PORTC.4
2. As PORTC.4 gets high, timer is started, and counts to predefined value (width of 1st pulse)
3. While timer is running, PORTC.4 is still being continuously checked, to determine, whenever it is still high. It should be high while timer is counting, if it gets low, while timer is on, this means, this is not proper pulse, so we should reset and start everything over.
4. If timer counting ended, and PORTC.4 was high all that time, this means that sync pulse was captured correctly, and we're ready for the next step.
This appears quite simple in words, but all Greek for me, in code, so far, my practical experience with timers and pwm is light dimming, and playing polyphonic tunes via it
![]()
Or Timer1 and Interrupt on Change or even better Interrupt on PortB.0 and use of Option_reg.6 to select which edge is expected to arrive and trigger the interrupt.
Needs a bit of work in the interrupt routine...
Ioannis
Indeed, but lack of knowledge....![]()
Code that works - It differentiates "0" from any other command:
Code:UIDEDA: if pulsi=0 then FOR N=0 TO 300 'main loop duration IF PULSI=0 THEN A=A+c 'count positive edges c=0 'stop increasing 1 after first loop d=1 'set increase for 0 ELSE B=B+d 'count 0 volt d=0 'stop increasing 0 after first loop c=1 'set increase for 1 ENDIF NEXT IF A<>0 AND B<>0 THEN lcdout $FE,2, "A=",#A, " " lcdout $FE,$C0,"B=",#B, " " ENDIF if a=7 and b=8 then high natura 'on if a=6 and b=7 then low natura 'off A=0 B=0 endif GOTO UIDEDA
Now I want to ad an array, where, when "1" occurs, value of N variable will be stored, which later can be counted, and position of "1" s and "0" -s detected.
Going totally crazy, can't figure out what to do and how![]()
Logically, code should look like this:
WAIT FOR LOW LEVEL AND MEASURE IT'S DURATION
IF LOW LEVEL LENGTH=10MS THEN MEASURE HIGH LEVEL DURATION AFTER IT
IF HIGH LEVEL DURATION WAS 2MS, THEN GO TO NEXT STEP, ELSE, LOOP THIS CYCLE AGAIN
NEXT LEVEL:
CONSIDER 600US LOW LEVEL AS 1, AND 2MS LOW LEVEL AS 0, WRITE THEM SEQUENTALY TO 32 BIT ARRAY, UNTIL 32 BITS WRITTEN
EXTRACT MSB AND LSB FROM ARRAY
CONVERT TO WORD
Bookmarks