How Can I Efficiently Program the PIC18F2520 for Money Detection and Validation?

  • Thread starter Thread starter Machtig
  • Start date Start date
AI Thread Summary
To efficiently program the PIC18F2520 for a smart park meter project, users are advised to utilize resources like tutorials on the Microchip website and familiarize themselves with MPLAB software. A strong understanding of C programming is recommended over assembly for better manageability, especially when interfacing with peripherals. The project involves detecting two types of coins and one type of paper money, with suggestions for using color detection and dimensional analysis for validation. Community support and online searches are essential for troubleshooting and finding solutions to common issues. Engaging deeply with the project and dedicating time to learning will be crucial for success.
Machtig
Messages
2
Reaction score
1
hello everyone,
I currently have to learn how to program the pic18f2520 for a project and I need to do it fast. So I was wondering if anyone has any reference (other than the datasheet of course) that can help me to learn or even any advice.

thank you
 
Engineering news on Phys.org
Machtig said:
hello everyone,
I currently have to learn how to program the pic18f2520 for a project and I need to do it fast. So I was wondering if anyone has any reference (other than the datasheet of course) that can help me to learn or even any advice.

thank you
Welcome to the PF.

What have you found in your searching so far? I'd imagine there are probably some good tutorials on the Microchip website. What development environment are you using? What language are you programming in? How much experience do you have with programming and microcontrollers (uCs)?
 
Also, what is the project? Are you loading your code into a Development Board (if so, which one?), or into existing hardware with that uC on it? What peripherals will you be interfacing with?
 
I learned to program in C at the same time as learning my first microcontroller which was the 18F2520. It's not likely something that will be quick and easy for you. I spent a lot of time reading. Just learning to navigate MPLAB was enough to make me want to turn away. I wanted it bad enough though, so I stuck with it. What is the project? Are you using mostly peripherals on chip or wiring to other devices?
-
My 'developement board' was a proto board with the 2520 wired up to a graphics display module. I went from there.
 
  • Like
Likes berkeman
There's no quick way to learn computer basics. Best way is to dive in as you are doing. Take it home over the weekend and plan on a lot of midnight oil.
Start with the examples on Microchip site.

If you are facing a project deadline consider using a BASIC micro instead. The interpreted Basic runs slow but is orders of magnitude easier to learn.

I used one of these for an emergency project -
http://www.micromint.com/products/by-family/modules.html?id=45
upload_2017-11-23_9-54-48.png


Had one week to order parts, design, build, program, debug and deliver. Made it thanks to the Boss's credit card and Steve Ciarcia's advice "Use Basic not assembly" .

old jim
 

Attachments

  • upload_2017-11-23_9-54-48.png
    upload_2017-11-23_9-54-48.png
    32.4 KB · Views: 484
Last edited:
  • Like
Likes dlgoff and berkeman
Purchase the following items:
Explorer 8 Eval board $78
Pickit3 $48
You can get these directly from Microchip, or from Digikey, Mouser etc.
Download and start getting familiar with the MPLAB sofware.

As the others mentioned, expect to burn some midnight oil. That's how a lot of us got up to speed on this stuff.
That said, be grateful that you are starting out with PIC, the alternatives have a steeper, less user friendly learning curve.

The overall process consists of the following:
1 - Architect the design (has this been done?)
Diagram out exactly how the uC is going to solve the problem at hand. What will the timers be used for. What will the ISRs need to do.
Don't assume you need a complicated RTOS, will a simple cyclic executive suffice? Keep it as simple as possible.

2- If you are unfamilar with C, learn it. You do not want to program this in assembly unless you need to for performance reasons. One of the the big advantages of the PIC18 series is the deep hardware stack which makes structured C programming possible, you don't have to worry if adding another function call will overflow the stack.

3 - Use a hardware abstraction layer. Create functions that are meaningful to your application, readBatteryVolts(). Your hardware abstraction layer will map these to PIC functions, ADCC_GetSingleConversion(channel_ANA5). This will help you keep your sanity and will also facilitate any future port of this code to a different uC. Others may consider this bloat, but I think it is a good idea unless you are up against speed or space limits.

4 - Write your application code.

5 - Use MPLAB to create the hardware facing functions that you need, and tie them together in your hardware abstraction layer.

6 - Finally, and probably most importantly, if you run into a problem, use online searches and communities (such as this one) to get help. Almost any problem that you encounter, someone else has already encountered and gotten help online. Just be very specific in your queries.

P.S. If you have not built your hardware yet, make sure you provide access to the programming pins so that you can configure your target hardware with PICkit3.
 
Last edited:
  • Like
Likes berkeman, jim hardy, Averagesupernova and 1 other person
Hello guys,

The project is a smart parkmeter that takes coins (2 types) and paper money (1 type) and detects when the car leaves.

We have to use pic18f2520, and the coding will be done with assembly using MPLAB.

So know our main concern is how to detect the money, we were thinking of having color detection and maybe having 2 slots using the dimensions of the coins.
So any ideas on that?
 
Real product or school project?
 
Machtig said:
So know our main concern is how to detect the money, we were thinking of having color detection and maybe having 2 slots using the dimensions of the coins.
So any ideas on that?
When you did your Google search on that, what did you find were typical techniques for money detection and validation? There is a LOT of information on this available...
 
Back
Top