Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F4620 Multi-Coin Slot Interfacing - Need Help

Status
Not open for further replies.

emerhidalgo

Newbie level 3
Newbie level 3
Joined
Nov 16, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
Good Morning Sir/Madam

I need some help with regards to this... Kindly help me please... :)

I made a counter program and circuit for the multi-coinslot with the following objectives

1. Count the pulse the output pulse of the coinslot

this was the schematic that I made which was now in an actual simulator

report.jpg

Here's the code written in MikroC Pro:

Code:
void main() {
  int counter = 0;
     //ADCON1 |= 1;
      //CMCON |= 7;
  TRISB = 0;
  PORTB = 0;
  while(1){
  if (PORTB.F2 == 1){
  counter++;
               if (counter==1){
               PORTB.F0 = 1;
               delay_ms(5000);
               }
               else if (counter>=2){
               PORTB.F1 = 1;
               delay_ms(5000);
               }
               delay_ms(5);
               
  }
}
}

The code objective was to turn on a LED whenever the counter increments itself by using the trigger PORTB.F2
On my assumption it will turn ON PORTB.F2 at a very fast time interval so I wrote this code just to see if it will works but unfortunately it doesn't :(

Am I missing something important?

Here's the document of the multi-coinslot that I used.
**broken link removed**

Here's the part list
- PIC18F4620
- Multi-Coin Slot Model: 623
- Crystal Oscillator 20MGHz
 

Attachments

  • attachment.rar
    114.1 KB · Views: 101
Last edited:

Thanks taroot I will try that and revert back to you asap... :)
 

Thanks dude, I'm a little confused about the logic...

I think I should use an Interrupt for this one coz I don't think that I can read the pulse by using the above code.

This is my new code.


int cnt;
void interrupt() {
if (TMR1IF_bit) {
cnt++; // Increment value of cnt on every interrupt
TMR1IF_bit = 0; // clear TMR1IF
}
if (cnt ==1){
PORTB.F0 = 1;
delay_ms(50);
}
if (cnt==2){
PORTB.F1 = 1;
delay_ms(50);
}
if (cnt==3){
PORTB.F0 = 0;
delay_ms(50);
PORTB.F1 = 0;
delay_ms(50);
cnt = 0;
}
}


void main() {
ADCON1 |= 0x0F;
CMCON |= 7;
T1CON = 0X0F;
INTCON = 0XC0;
PIE1 = 0X01;

TRISB = 0;
PORTB = 0;
{
}
}


I put the counter pin of the multicoinslot to RX pin of the MCU...
I managed to get a blinking led result. F0 = 1 F1 = 1 F0 and F1 = 0, but I haven't inserted a coin yet. Jeez! Im so confused..

btw can you read interrupt in PORTB.F2?
 

Use External interrupt (PORTB) to count the coin pulse. when you insert a coin you will get interrupt and use counter with it.
void interrupt() {

if(INT0IF_bit) { // Rising Edge
INT0IF_bit = 0;
counter++;
}
 
Thanks for helping us out taroot... I really appreciate your help... but unfortunately I can't try that solution right now... I'm working on a different project this week... I'll let you know if the solution works when I'm done :) Thanks a lot dude.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top