• AVR Freaks

Hot!38KHz with Timer0 PIC16F648A

Page: < 123 Showing page 3 of 3
Author
ounvme
Starting Member
  • Total Posts : 65
  • Reward points : 0
  • Joined: 2012/03/10 13:35:40
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/14 20:57:25 (permalink)
0
The level of intelligence you guys have is mind blowing. I truly do appreciate all of this information. dan1138, I tested your code and the volume up did work flawlessly with an 8MHz crystal. The special thing about this is all of these REDI REMOTES are the same so I can essentially use them to replace or create any IR remote needed. I hope someone else will benefit from this. I do want to stick with the 4MHz crystal on the board. I am sure that it is obvious but I am no coder. I am going to step through each of these examples until I understand them and it works. Switch or IF statements for the button matrix or it doesn't matter? pcbbc, I will study your examples next.
#41
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/15 02:18:37 (permalink)
0
ounvmeThe level of intelligence you guys have is mind blowing.
Well, for me it’s just a misspent youth of pulling things I probably shouldn’t have apart!

Sometimes it’s fun just to have a puzzle, and I think you share that because otherwise you wouldn’t have started on this exercise.

dan1138, I tested your code and the volume up did work flawlessly with an 8MHz crystal.
Great bit of coding there by Dan!

The special thing about this is all of these REDI REMOTES are the same so I can essentially use them to replace or create any IR remote needed. I hope someone else will benefit from this. I do want to stick with the 4MHz crystal on the board.
Well, it’s an interesting exercise in reverse engineering. And a good starter project and introduction/crash course in IR protocols.

I am sure that it is obvious but I am no coder. I am going to step through each of these examples until I understand them and it works.
Dont worry, it will come. You obviously have an interest, and are willing to study and work things out. That’s all it takes really.

Switch or IF statements for the button matrix or it doesn't matter? pcbbc, I will study your examples next.
Either will work, but you are going to require a lot of coding if you are testing each and every button combination individually.

Probably easiest overall is going to end up a few nested loops and some lookup tables.
You have 11 bits, which are going to be spread over more than one port, so it is not quite this simple, but something like...
//configure for first matrix (5 outputs 6 inputs)
keytest = 0;
keypressed = -1;
for (row = 0; row < 5; row++) {
//output row bit to row drivers, tristate all other row bits
//this is a lookup table (rowbitsX) of row to bit in an output PORTX
for (col = 0; col < 6; col++) {
if ((PORTX & colbitsX[col]) == 0)
{
keypressed = keytest;
}
keytest++;
}
}
//configure for reverse second matrix (6 outputs 5 inputs)
for (col = 0; col < 6; col++) {
//output col bit to column drivers, tristate all other column bits
//this is the colbitsX lookup table you see above, just used to drive
//the same pin(s) output in PORTX instead of testing for input
for (row = 0; row < 5; row++) {
if ((PORTX & rowbitsX[row]) == 0)
{
keypressed = keytest;
}
keytest++;
}
}
if (keypressed >= 0)
{
//send ir code from lookup table index “keypressed”
}

Hopefully enough to get you started.

Edit: Note I also assumed negative logic on the keys (test for zero on input port bit) with pull-up resistors.
It may be positive logic (test for not zero) with pull-down resistors.
You’ll need to check which they are using by looking at the resistors and diode directions.
post edited by pcbbc - 2019/03/15 02:26:52
#42
ounvme
Starting Member
  • Total Posts : 65
  • Reward points : 0
  • Joined: 2012/03/10 13:35:40
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/16 00:13:01 (permalink)
0
I am combining some of the proposed ideas to roll my own creation. I am struggling a little bit with creating an accurate inline delay in assembly. 
asm(" cblock");
 asm(" d1");
 asm(" d2");
 asm(" endc");
 
 asm(" movlw 0x8F");
 asm(" movwf d1");
 asm(" movlw 0x02");
 asm(" movwf d2");
 asm(" Delay_0");
 asm(" decfsz d1, f");
 asm(" goto $+2");
 asm(" decfsz d2, f");
 asm(" goto Delay_0");
 asm(" ;2 cycles");
 asm(" goto $+1");

 
Granted I got this snippet from an ASM delay generator, I kinda get what it wants to do but I don't fully understand and I get a compile error.
main_ISR.c:149:: error: (1356) fixup overflow referencing psect text1 (0x736) into 1 byte at 0xE6E/0x2 -> 0x737 (dist/default/production\16F648A.X.production.o 37/0x18)
 
4 errors in total and they happen on the lines with d1 and d2 so I assume it does not like that name or data type. I also would like this to accept a value that is passed to the function. 
 
I can do it with this but it has 14uS of overhead for each cycle of the loop and __delay_us() cant take a variable.
do //40uS OverHead 
    {
     //_delay(2); // 20/4 - 3 instruction cycles ( 3 is the loop overhead)
     asm(" nop");
    }
    while(--code1);

 
 
#43
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/16 01:06:29 (permalink)
+1 (1)
Those lines are trying to declare 2 bytes of storage (file registers in pic nomleculture), called d1 and d2.
I’m not sure that is correct for inline assembly. Usually you’d declare the variable in the C code and reference that.

Inline asm directive is fine if you want to insert a few instructions into the middle of an existing C routine.
But unwealdy and clunky if you are trying to write an entire function.
In that case you are better to add an external assembler file to your project and create a hybrid c/asm solution.

I’ll try and find you an example...
#44
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/16 01:37:18 (permalink)
0
volatile uint16_t delay;

void main(void) {
    delay = 0x105;
    asm("  BANKSEL _delay");
    asm("  incf (_delay+1)&0x7F, f");
    asm("loop:");
    asm("  decfsz (_delay+0)&0x7F, f");
    asm("  goto loop");
    asm("  decfsz (_delay+1)&0x7F, f");
    asm("  goto loop");
    return;
}

It seems to me however you are heading for the whole IR code, 38KHz and delays, coded in assembler.  This seems more work than necessary, and isn't best suited to inline asm.  Although as an exercise in learning assembler it is fine!
 
For how to integrate assembly modules with your C code, see the XC8 user manual:
C:\Program Files (x86)\Microchip\xc8\v2.05\docs\MPLAB_XC8_C_Compiler_User_Guide_for_PIC.pdf
Section 4.12.1 Integrating Assembly Language Modules
post edited by pcbbc - 2019/03/16 01:41:34
#45
ounvme
Starting Member
  • Total Posts : 65
  • Reward points : 0
  • Joined: 2012/03/10 13:35:40
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/28 19:39:56 (permalink)
0
Small update:
 
I managed to get all of the codes tested and replicated. I am using a mashup of ASM and some functions. I found out why the buttons have overlap when measured. The PIC sends a pulse to each key grid pin. While that pin is H it scans the remaining pins to see what other pin is pulled H from the button press. All that is left is to finish the code, test it and I will post what I have and what it is actually for.
#46
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: 38KHz with Timer0 PIC16F648A 2019/03/28 23:06:11 (permalink)
+1 (1)
Well done.

ounvmeI found out why the buttons have overlap when measured. The PIC sends a pulse to each key grid pin. While that pin is H it scans the remaining pins to see what other pin is pulled H from the button press. All that is left is to finish the code, test it and I will post what I have and what it is actually for.
This isn’t why they have overlap. What you have described there is basically a standard keyboard matrix, which with 11 pins can only scan a maximal 6x5 grid = 30 keys (without any external circuitry or components other than the keys). If you’d have tested such a matrix you would have found NO overlap.

The reason you have overlap is because of the external diodes in the matrix which allow for two keys on each and every combination of 2 pins. Which key is pressed is detected by driving in opposite directions, and the diodes blocking half of the keys on the row/column side key such that it effectively only allow one key per pin at a time.

Looking forward to the update.
#47
Page: < 123 Showing page 3 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5